# coding: utf-8

"""
    Docling Serve

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from yfkm3_services_parse_client.models.api_model_config import ApiModelConfig
from yfkm3_services_parse_client.models.engine_model_config import EngineModelConfig
from yfkm3_services_parse_client.models.response_format import ResponseFormat
from yfkm3_services_parse_client.models.vlm_engine_type import VlmEngineType
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class VlmModelSpec(BaseModel):
    """
    Specification for a VLM model.  This defines the model configuration that is independent of the engine. It includes: - Default model repository ID - Prompt template - Response format - Engine-specific overrides
    """ # noqa: E501
    name: StrictStr = Field(description="Human-readable model name")
    default_repo_id: StrictStr = Field(description="Default HuggingFace repository ID")
    revision: Optional[StrictStr] = Field(default='main', description="Default model revision")
    prompt: StrictStr = Field(description="Prompt template for this model")
    response_format: ResponseFormat = Field(description="Expected response format from the model")
    supported_engines: Optional[List[VlmEngineType]] = None
    engine_overrides: Optional[Dict[str, EngineModelConfig]] = Field(default=None, description="Engine-specific configuration overrides")
    api_overrides: Optional[Dict[str, ApiModelConfig]] = Field(default=None, description="API-specific configuration overrides")
    trust_remote_code: Optional[StrictBool] = Field(default=False, description="Whether to trust remote code for this model")
    stop_strings: Optional[List[StrictStr]] = Field(default=None, description="Stop strings for generation")
    max_new_tokens: Optional[StrictInt] = Field(default=4096, description="Maximum number of new tokens to generate")
    __properties: ClassVar[List[str]] = ["name", "default_repo_id", "revision", "prompt", "response_format", "supported_engines", "engine_overrides", "api_overrides", "trust_remote_code", "stop_strings", "max_new_tokens"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of VlmModelSpec from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each value in engine_overrides (dict)
        _field_dict = {}
        if self.engine_overrides:
            for _key_engine_overrides in self.engine_overrides:
                if self.engine_overrides[_key_engine_overrides]:
                    _field_dict[_key_engine_overrides] = self.engine_overrides[_key_engine_overrides].to_dict()
            _dict['engine_overrides'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in api_overrides (dict)
        _field_dict = {}
        if self.api_overrides:
            for _key_api_overrides in self.api_overrides:
                if self.api_overrides[_key_api_overrides]:
                    _field_dict[_key_api_overrides] = self.api_overrides[_key_api_overrides].to_dict()
            _dict['api_overrides'] = _field_dict
        # set to None if supported_engines (nullable) is None
        # and model_fields_set contains the field
        if self.supported_engines is None and "supported_engines" in self.model_fields_set:
            _dict['supported_engines'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of VlmModelSpec from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "default_repo_id": obj.get("default_repo_id"),
            "revision": obj.get("revision") if obj.get("revision") is not None else 'main',
            "prompt": obj.get("prompt"),
            "response_format": obj.get("response_format"),
            "supported_engines": obj.get("supported_engines"),
            "engine_overrides": dict(
                (_k, EngineModelConfig.from_dict(_v))
                for _k, _v in obj["engine_overrides"].items()
            )
            if obj.get("engine_overrides") is not None
            else None,
            "api_overrides": dict(
                (_k, ApiModelConfig.from_dict(_v))
                for _k, _v in obj["api_overrides"].items()
            )
            if obj.get("api_overrides") is not None
            else None,
            "trust_remote_code": obj.get("trust_remote_code") if obj.get("trust_remote_code") is not None else False,
            "stop_strings": obj.get("stop_strings"),
            "max_new_tokens": obj.get("max_new_tokens") if obj.get("max_new_tokens") is not None else 4096
        })
        return _obj


