# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from civitai_py.models.parameter_attributes import ParameterAttributes
from typing import Optional, Set
from typing_extensions import Self


class ParameterInfo(BaseModel):
    """
from civitai_py.models.custom_attribute_data import CustomAttributeData
from civitai_py.models.type import Type
from civitai_py.models.member_info import MemberInfo
    ParameterInfo
    """  # noqa: E501
    attributes: Optional[ParameterAttributes] = None
    member: Optional[MemberInfo] = None
    name: Optional[StrictStr] = None
    parameter_type: Optional[Type] = Field(default=None, alias="parameterType")
    position: Optional[StrictInt] = None
    is_in: Optional[StrictBool] = Field(default=None, alias="isIn")
    is_lcid: Optional[StrictBool] = Field(default=None, alias="isLcid")
    is_optional: Optional[StrictBool] = Field(default=None, alias="isOptional")
    is_out: Optional[StrictBool] = Field(default=None, alias="isOut")
    is_retval: Optional[StrictBool] = Field(default=None, alias="isRetval")
    default_value: Optional[Any] = Field(default=None, alias="defaultValue")
    raw_default_value: Optional[Any] = Field(default=None, alias="rawDefaultValue")
    has_default_value: Optional[StrictBool] = Field(default=None, alias="hasDefaultValue")
    custom_attributes: Optional[List[CustomAttributeData]
                                ] = Field(default=None, alias="customAttributes")
    metadata_token: Optional[StrictInt] = Field(default=None, alias="metadataToken")
    __properties: ClassVar[List[str]] = ["attributes", "member", "name", "parameterType", "position", "isIn", "isLcid",
                                         "isOptional", "isOut", "isRetval", "defaultValue", "rawDefaultValue", "hasDefaultValue", "customAttributes", "metadataToken"]

    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 ParameterInfo 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.
        * 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "name",
            "position",
            "is_in",
            "is_lcid",
            "is_optional",
            "is_out",
            "is_retval",
            "default_value",
            "raw_default_value",
            "has_default_value",
            "custom_attributes",
            "metadata_token",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of member
        if self.member:
            _dict['member'] = self.member.to_dict()
        # override the default output from pydantic by calling `to_dict()` of parameter_type
        if self.parameter_type:
            _dict['parameterType'] = self.parameter_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in custom_attributes (list)
        _items = []
        if self.custom_attributes:
            for _item in self.custom_attributes:
                if _item:
                    _items.append(_item.to_dict())
            _dict['customAttributes'] = _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 default_value (nullable) is None
        # and model_fields_set contains the field
        if self.default_value is None and "default_value" in self.model_fields_set:
            _dict['defaultValue'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "attributes": obj.get("attributes"),
            "member": MemberInfo.from_dict(obj["member"]) if obj.get("member") is not None else None,
            "name": obj.get("name"),
            "parameterType": Type.from_dict(obj["parameterType"]) if obj.get("parameterType") is not None else None,
            "position": obj.get("position"),
            "isIn": obj.get("isIn"),
            "isLcid": obj.get("isLcid"),
            "isOptional": obj.get("isOptional"),
            "isOut": obj.get("isOut"),
            "isRetval": obj.get("isRetval"),
            "defaultValue": obj.get("defaultValue"),
            "rawDefaultValue": obj.get("rawDefaultValue"),
            "hasDefaultValue": obj.get("hasDefaultValue"),
            "customAttributes": [CustomAttributeData.from_dict(_item) for _item in obj["customAttributes"]] if obj.get("customAttributes") is not None else None,
            "metadataToken": obj.get("metadataToken")
        })
        return _obj


# TODO: Rewrite to not use raise_errors
ParameterInfo.model_rebuild(raise_errors=False)
