# coding: utf-8

"""
    Civitai Orchestration Consumer API

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

    The version of the OpenAPI document: v1
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from civitai_py.models.base_model import SDBaseModel
from civitai_py.models.read_only_span1 import ReadOnlySpan1
from typing import Optional, Set
from typing_extensions import Self


class AIR(BaseModel):
    """
    AIR
    """  # noqa: E501
    value: Optional[StrictStr] = None
    legacy_id: Optional[StrictStr] = Field(default=None, alias="legacyId")
    base_model: Optional[SDBaseModel] = Field(default=None, alias="baseModel")
    ecosystem: Optional[ReadOnlySpan1] = None
    type: Optional[ReadOnlySpan1] = None
    source: Optional[ReadOnlySpan1] = None
    id: Optional[ReadOnlySpan1] = None
    layer: Optional[ReadOnlySpan1] = None
    format: Optional[ReadOnlySpan1] = None
    __properties: ClassVar[List[str]] = ["value", "legacyId", "baseModel",
                                         "ecosystem", "type", "source", "id", "layer", "format"]

    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 AIR 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.
        """
        excluded_fields: Set[str] = set([
            "legacy_id",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of ecosystem
        if self.ecosystem:
            _dict['ecosystem'] = self.ecosystem.to_dict()
        # override the default output from pydantic by calling `to_dict()` of type
        if self.type:
            _dict['type'] = self.type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of id
        if self.id:
            _dict['id'] = self.id.to_dict()
        # override the default output from pydantic by calling `to_dict()` of layer
        if self.layer:
            _dict['layer'] = self.layer.to_dict()
        # override the default output from pydantic by calling `to_dict()` of format
        if self.format:
            _dict['format'] = self.format.to_dict()
        # set to None if value (nullable) is None
        # and model_fields_set contains the field
        if self.value is None and "value" in self.model_fields_set:
            _dict['value'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "value": obj.get("value"),
            "legacyId": obj.get("legacyId"),
            "baseModel": obj.get("baseModel"),
            "ecosystem": ReadOnlySpan1.from_dict(obj["ecosystem"]) if obj.get("ecosystem") is not None else None,
            "type": ReadOnlySpan1.from_dict(obj["type"]) if obj.get("type") is not None else None,
            "source": ReadOnlySpan1.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "id": ReadOnlySpan1.from_dict(obj["id"]) if obj.get("id") is not None else None,
            "layer": ReadOnlySpan1.from_dict(obj["layer"]) if obj.get("layer") is not None else None,
            "format": ReadOnlySpan1.from_dict(obj["format"]) if obj.get("format") is not None else None
        })
        return _obj
