# coding: utf-8

"""
    AI Stats Gateway API

    Programmatic access to the AI Stats AI Gateway. All endpoints forward requests to the best available provider for the specified model, and return normalised responses with clear structured metadata.

    The version of the OpenAPI document: 0.1.0
    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 date
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from ai_stats_generated.models.gateway_model_provider import GatewayModelProvider
from ai_stats_generated.models.organisation_id import OrganisationId
from typing import Optional, Set
from typing_extensions import Self

class GatewayModel(BaseModel):
    """
    GatewayModel
    """ # noqa: E501
    model_id: StrictStr = Field(description="Canonical model identifier.")
    name: Optional[StrictStr] = Field(description="Human readable model name.")
    release_date: Optional[date] = Field(description="Earliest known public release date.")
    announcement_date: Optional[date] = Field(description="Earliest known public announcement date if different from release.")
    status: Optional[StrictStr] = Field(description="Lifecycle status of the model (Rumoured, Announced, Available, Deprecated, Retired).")
    organisation: Optional[OrganisationId]
    aliases: List[StrictStr] = Field(description="Enabled aliases that resolve to this model.")
    endpoints: List[StrictStr] = Field(description="Gateway endpoints that currently route to this model.")
    providers: List[GatewayModelProvider] = Field(description="Provider mappings that can serve this model.")
    input_types: List[StrictStr] = Field(description="Input content types supported by the model itself.")
    output_types: List[StrictStr] = Field(description="Output content types supported by the model itself.")
    __properties: ClassVar[List[str]] = ["model_id", "name", "release_date", "announcement_date", "status", "organisation", "aliases", "endpoints", "providers", "input_types", "output_types"]

    @field_validator('endpoints')
    def endpoints_validate_enum(cls, value):
        """Validates the enum"""
        for i in value:
            if i not in set(['chat.completions', 'images.generations', 'audio.speech', 'audio.transcription', 'moderations', 'video.generation', 'embeddings', 'batch']):
                raise ValueError("each list item must be one of ('chat.completions', 'images.generations', 'audio.speech', 'audio.transcription', 'moderations', 'video.generation', 'embeddings', 'batch')")
        return value

    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 GatewayModel 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 item in providers (list)
        _items = []
        if self.providers:
            for _item_providers in self.providers:
                if _item_providers:
                    _items.append(_item_providers.to_dict())
            _dict['providers'] = _items
        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['name'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "model_id": obj.get("model_id"),
            "name": obj.get("name"),
            "release_date": obj.get("release_date"),
            "announcement_date": obj.get("announcement_date"),
            "status": obj.get("status"),
            "organisation": obj.get("organisation"),
            "aliases": obj.get("aliases"),
            "endpoints": obj.get("endpoints"),
            "providers": [GatewayModelProvider.from_dict(_item) for _item in obj["providers"]] if obj.get("providers") is not None else None,
            "input_types": obj.get("input_types"),
            "output_types": obj.get("output_types")
        })
        return _obj


