# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 4.202.1-ai-plus
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class ClawModelProvider(BaseModel):
    """
    ClawModelProvider
    """ # noqa: E501
    id: StrictInt
    server: StrictInt
    server_name: StrictStr
    name: Annotated[str, Field(strict=True, max_length=100)] = Field(description="Provider identifier in the Claw config (e.g. 'minimax')")
    base_url: Annotated[str, Field(strict=True, max_length=200)] = Field(description="Provider API endpoint (e.g. https://api.minimax.io/anthropic)")
    api_type: Annotated[str, Field(strict=True, max_length=50)] = Field(description="Claw provider API type (e.g. 'openai-completions', 'anthropic-messages').")
    credential_name: Annotated[str, Field(strict=True, max_length=255)] = Field(description="Name of the LLMCredential to resolve the API key from")
    credential_key: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="Key within the LLMCredential value JSON to extract the API key")
    model_catalog: Optional[Any] = Field(default=None, description="List of {\"id\": \"...\", \"name\": \"...\"} entries for the provider model catalog")
    enabled: Optional[StrictBool] = None
    models_mode: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="'merge' adds to built-in models, 'replace' uses only configured providers.")
    last_provider_push: Optional[datetime]
    last_provider_push_status: Optional[StrictStr]
    credential_resolved: StrictBool = Field(description="Check if the referenced LLMCredential exists for this platform.")
    __properties: ClassVar[List[str]] = ["id", "server", "server_name", "name", "base_url", "api_type", "credential_name", "credential_key", "model_catalog", "enabled", "models_mode", "last_provider_push", "last_provider_push_status", "credential_resolved"]

    model_config = ConfigDict(
        populate_by_name=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"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ClawModelProvider 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "server_name",
            "last_provider_push",
            "last_provider_push_status",
            "credential_resolved",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if model_catalog (nullable) is None
        # and model_fields_set contains the field
        if self.model_catalog is None and "model_catalog" in self.model_fields_set:
            _dict['model_catalog'] = None

        # set to None if last_provider_push (nullable) is None
        # and model_fields_set contains the field
        if self.last_provider_push is None and "last_provider_push" in self.model_fields_set:
            _dict['last_provider_push'] = None

        # set to None if last_provider_push_status (nullable) is None
        # and model_fields_set contains the field
        if self.last_provider_push_status is None and "last_provider_push_status" in self.model_fields_set:
            _dict['last_provider_push_status'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "server": obj.get("server"),
            "server_name": obj.get("server_name"),
            "name": obj.get("name"),
            "base_url": obj.get("base_url"),
            "api_type": obj.get("api_type"),
            "credential_name": obj.get("credential_name"),
            "credential_key": obj.get("credential_key"),
            "model_catalog": obj.get("model_catalog"),
            "enabled": obj.get("enabled"),
            "models_mode": obj.get("models_mode"),
            "last_provider_push": obj.get("last_provider_push"),
            "last_provider_push_status": obj.get("last_provider_push_status"),
            "credential_resolved": obj.get("credential_resolved")
        })
        return _obj


