# 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.field_attributes import FieldAttributes
from civitai_py.models.member_types import MemberTypes
from civitai_py.models.runtime_field_handle import RuntimeFieldHandle
from typing import Optional, Set
from typing_extensions import Self


class FieldInfo(BaseModel):
    """
from civitai_py.models.custom_attribute_data import CustomAttributeData
from civitai_py.models.type import Type
from civitai_py.models.module import Module
    FieldInfo
    """  # noqa: E501
    name: Optional[StrictStr] = None
    declaring_type: Optional[Type] = Field(default=None, alias="declaringType")
    reflected_type: Optional[Type] = Field(default=None, alias="reflectedType")
    module: Optional[Module] = None
    custom_attributes: Optional[List[CustomAttributeData]
                                ] = Field(default=None, alias="customAttributes")
    is_collectible: Optional[StrictBool] = Field(default=None, alias="isCollectible")
    metadata_token: Optional[StrictInt] = Field(default=None, alias="metadataToken")
    member_type: Optional[MemberTypes] = Field(default=None, alias="memberType")
    attributes: Optional[FieldAttributes] = None
    field_type: Optional[Type] = Field(default=None, alias="fieldType")
    is_init_only: Optional[StrictBool] = Field(default=None, alias="isInitOnly")
    is_literal: Optional[StrictBool] = Field(default=None, alias="isLiteral")
    is_pinvoke_impl: Optional[StrictBool] = Field(default=None, alias="isPinvokeImpl")
    is_special_name: Optional[StrictBool] = Field(default=None, alias="isSpecialName")
    is_static: Optional[StrictBool] = Field(default=None, alias="isStatic")
    is_assembly: Optional[StrictBool] = Field(default=None, alias="isAssembly")
    is_family: Optional[StrictBool] = Field(default=None, alias="isFamily")
    is_family_and_assembly: Optional[StrictBool] = Field(default=None, alias="isFamilyAndAssembly")
    is_family_or_assembly: Optional[StrictBool] = Field(default=None, alias="isFamilyOrAssembly")
    is_private: Optional[StrictBool] = Field(default=None, alias="isPrivate")
    is_public: Optional[StrictBool] = Field(default=None, alias="isPublic")
    is_security_critical: Optional[StrictBool] = Field(default=None, alias="isSecurityCritical")
    is_security_safe_critical: Optional[StrictBool] = Field(
        default=None, alias="isSecuritySafeCritical")
    is_security_transparent: Optional[StrictBool] = Field(
        default=None, alias="isSecurityTransparent")
    field_handle: Optional[RuntimeFieldHandle] = Field(default=None, alias="fieldHandle")
    __properties: ClassVar[List[str]] = ["name", "declaringType", "reflectedType", "module", "customAttributes", "isCollectible", "metadataToken", "memberType", "attributes", "fieldType", "isInitOnly", "isLiteral", "isPinvokeImpl",
                                         "isSpecialName", "isStatic", "isAssembly", "isFamily", "isFamilyAndAssembly", "isFamilyOrAssembly", "isPrivate", "isPublic", "isSecurityCritical", "isSecuritySafeCritical", "isSecurityTransparent", "fieldHandle"]

    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 FieldInfo 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.
        * 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",
            "custom_attributes",
            "is_collectible",
            "metadata_token",
            "is_init_only",
            "is_literal",
            "is_pinvoke_impl",
            "is_special_name",
            "is_static",
            "is_assembly",
            "is_family",
            "is_family_and_assembly",
            "is_family_or_assembly",
            "is_private",
            "is_public",
            "is_security_critical",
            "is_security_safe_critical",
            "is_security_transparent",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of declaring_type
        if self.declaring_type:
            _dict['declaringType'] = self.declaring_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of reflected_type
        if self.reflected_type:
            _dict['reflectedType'] = self.reflected_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of module
        if self.module:
            _dict['module'] = self.module.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
        # override the default output from pydantic by calling `to_dict()` of field_type
        if self.field_type:
            _dict['fieldType'] = self.field_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of field_handle
        if self.field_handle:
            _dict['fieldHandle'] = self.field_handle.to_dict()
        # 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 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 FieldInfo from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "declaringType": Type.from_dict(obj["declaringType"]) if obj.get("declaringType") is not None else None,
            "reflectedType": Type.from_dict(obj["reflectedType"]) if obj.get("reflectedType") is not None else None,
            "module": Module.from_dict(obj["module"]) if obj.get("module") is not None else None,
            "customAttributes": [CustomAttributeData.from_dict(_item) for _item in obj["customAttributes"]] if obj.get("customAttributes") is not None else None,
            "isCollectible": obj.get("isCollectible"),
            "metadataToken": obj.get("metadataToken"),
            "memberType": obj.get("memberType"),
            "attributes": obj.get("attributes"),
            "fieldType": Type.from_dict(obj["fieldType"]) if obj.get("fieldType") is not None else None,
            "isInitOnly": obj.get("isInitOnly"),
            "isLiteral": obj.get("isLiteral"),
            "isPinvokeImpl": obj.get("isPinvokeImpl"),
            "isSpecialName": obj.get("isSpecialName"),
            "isStatic": obj.get("isStatic"),
            "isAssembly": obj.get("isAssembly"),
            "isFamily": obj.get("isFamily"),
            "isFamilyAndAssembly": obj.get("isFamilyAndAssembly"),
            "isFamilyOrAssembly": obj.get("isFamilyOrAssembly"),
            "isPrivate": obj.get("isPrivate"),
            "isPublic": obj.get("isPublic"),
            "isSecurityCritical": obj.get("isSecurityCritical"),
            "isSecuritySafeCritical": obj.get("isSecuritySafeCritical"),
            "isSecurityTransparent": obj.get("isSecurityTransparent"),
            "fieldHandle": RuntimeFieldHandle.from_dict(obj["fieldHandle"]) if obj.get("fieldHandle") is not None else None
        })
        return _obj


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