# 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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from iblai.models.name_enum import NameEnum
from iblai.models.scope_c1d_enum import ScopeC1dEnum
from typing import Optional, Set
from typing_extensions import Self

class FallbackLLMCreate(BaseModel):
    """
    Serializer for creating FallbackLLM configuration.
    """ # noqa: E501
    scope: Optional[ScopeC1dEnum] = Field(default=None, description="Whether this fallback applies to a specific model or entire provider  * `model` - Model Specific * `provider` - Provider Wide")
    tenant_key: Optional[StrictStr] = Field(default=None, description="Tenant key. Leave empty for global configuration.")
    source_provider_name: NameEnum = Field(description="Source provider name (e.g., 'openai')")
    source_model_name: Optional[StrictStr] = Field(default=None, description="Source model name (required for model scope)")
    fallback_provider_name: NameEnum = Field(description="Fallback provider name")
    fallback_model_name: StrictStr = Field(description="Fallback model name")
    is_enabled: Optional[StrictBool] = Field(default=None, description="Whether this fallback configuration is active")
    __properties: ClassVar[List[str]] = ["scope", "tenant_key", "source_provider_name", "source_model_name", "fallback_provider_name", "fallback_model_name", "is_enabled"]

    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 FallbackLLMCreate 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,
        )
        # set to None if tenant_key (nullable) is None
        # and model_fields_set contains the field
        if self.tenant_key is None and "tenant_key" in self.model_fields_set:
            _dict['tenant_key'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "scope": obj.get("scope"),
            "tenant_key": obj.get("tenant_key"),
            "source_provider_name": obj.get("source_provider_name"),
            "source_model_name": obj.get("source_model_name"),
            "fallback_provider_name": obj.get("fallback_provider_name"),
            "fallback_model_name": obj.get("fallback_model_name"),
            "is_enabled": obj.get("is_enabled")
        })
        return _obj


