# 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.security_rule_set import SecurityRuleSet
from typing import Optional, Set
from typing_extensions import Self


class Assembly(BaseModel):
    """
from civitai_py.models.custom_attribute_data import CustomAttributeData
from civitai_py.models.type_info import TypeInfo
from civitai_py.models.type import Type
from civitai_py.models.module import Module
from civitai_py.models.method_info import MethodInfo
    Assembly
    """  # noqa: E501
    defined_types: Optional[List[TypeInfo]] = Field(default=None, alias="definedTypes")
    exported_types: Optional[List[Type]] = Field(default=None, alias="exportedTypes")
    entry_point: Optional[MethodInfo] = Field(default=None, alias="entryPoint")
    full_name: Optional[StrictStr] = Field(default=None, alias="fullName")
    image_runtime_version: Optional[StrictStr] = Field(default=None, alias="imageRuntimeVersion")
    is_dynamic: Optional[StrictBool] = Field(default=None, alias="isDynamic")
    location: Optional[StrictStr] = None
    reflection_only: Optional[StrictBool] = Field(default=None, alias="reflectionOnly")
    is_collectible: Optional[StrictBool] = Field(default=None, alias="isCollectible")
    is_fully_trusted: Optional[StrictBool] = Field(default=None, alias="isFullyTrusted")
    custom_attributes: Optional[List[CustomAttributeData]
                                ] = Field(default=None, alias="customAttributes")
    manifest_module: Optional[Module] = Field(default=None, alias="manifestModule")
    modules: Optional[List[Module]] = None
    host_context: Optional[StrictInt] = Field(default=None, alias="hostContext")
    security_rule_set: Optional[SecurityRuleSet] = Field(default=None, alias="securityRuleSet")
    __properties: ClassVar[List[str]] = ["definedTypes", "exportedTypes", "entryPoint", "fullName", "imageRuntimeVersion", "isDynamic", "location",
                                         "reflectionOnly", "isCollectible", "isFullyTrusted", "customAttributes", "manifestModule", "modules", "hostContext", "securityRuleSet"]

    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 Assembly 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([
            "defined_types",
            "exported_types",
            "full_name",
            "image_runtime_version",
            "is_dynamic",
            "location",
            "reflection_only",
            "is_collectible",
            "is_fully_trusted",
            "custom_attributes",
            "modules",
            "host_context",
        ])

        _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 defined_types (list)
        _items = []
        if self.defined_types:
            for _item in self.defined_types:
                if _item:
                    _items.append(_item.to_dict())
            _dict['definedTypes'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in exported_types (list)
        _items = []
        if self.exported_types:
            for _item in self.exported_types:
                if _item:
                    _items.append(_item.to_dict())
            _dict['exportedTypes'] = _items
        # override the default output from pydantic by calling `to_dict()` of entry_point
        if self.entry_point:
            _dict['entryPoint'] = self.entry_point.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 manifest_module
        if self.manifest_module:
            _dict['manifestModule'] = self.manifest_module.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in modules (list)
        _items = []
        if self.modules:
            for _item in self.modules:
                if _item:
                    _items.append(_item.to_dict())
            _dict['modules'] = _items
        # set to None if defined_types (nullable) is None
        # and model_fields_set contains the field
        if self.defined_types is None and "defined_types" in self.model_fields_set:
            _dict['definedTypes'] = None

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "definedTypes": [TypeInfo.from_dict(_item) for _item in obj["definedTypes"]] if obj.get("definedTypes") is not None else None,
            "exportedTypes": [Type.from_dict(_item) for _item in obj["exportedTypes"]] if obj.get("exportedTypes") is not None else None,
            "entryPoint": MethodInfo.from_dict(obj["entryPoint"]) if obj.get("entryPoint") is not None else None,
            "fullName": obj.get("fullName"),
            "imageRuntimeVersion": obj.get("imageRuntimeVersion"),
            "isDynamic": obj.get("isDynamic"),
            "location": obj.get("location"),
            "reflectionOnly": obj.get("reflectionOnly"),
            "isCollectible": obj.get("isCollectible"),
            "isFullyTrusted": obj.get("isFullyTrusted"),
            "customAttributes": [CustomAttributeData.from_dict(_item) for _item in obj["customAttributes"]] if obj.get("customAttributes") is not None else None,
            "manifestModule": Module.from_dict(obj["manifestModule"]) if obj.get("manifestModule") is not None else None,
            "modules": [Module.from_dict(_item) for _item in obj["modules"]] if obj.get("modules") is not None else None,
            "hostContext": obj.get("hostContext"),
            "securityRuleSet": obj.get("securityRuleSet")
        })
        return _obj


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