# coding: utf-8

"""
    Snowstorm

    SNOMED CT Terminology Server REST API

    The version of the OpenAPI document: 10.8.2
    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 datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from snowstorm_client.models.annotation import Annotation
from snowstorm_client.models.axiom import Axiom
from snowstorm_client.models.description import Description
from snowstorm_client.models.identifier import Identifier
from snowstorm_client.models.invalid_content import InvalidContent
from snowstorm_client.models.reference_set_member import ReferenceSetMember
from snowstorm_client.models.relationship import Relationship
from snowstorm_client.models.term_lang_pojo import TermLangPojo
from typing import Optional, Set
from typing_extensions import Self

class Concept(BaseModel):
    """
    Concept
    """ # noqa: E501
    concept_id: Optional[Annotated[str, Field(min_length=5, strict=True, max_length=18)]] = Field(default=None, alias="conceptId")
    descendant_count: Optional[StrictInt] = Field(default=None, alias="descendantCount")
    fsn: Optional[TermLangPojo] = None
    pt: Optional[TermLangPojo] = None
    active: Optional[StrictBool] = None
    effective_time: Optional[StrictStr] = Field(default=None, alias="effectiveTime")
    released: Optional[StrictBool] = None
    released_effective_time: Optional[StrictInt] = Field(default=None, alias="releasedEffectiveTime")
    inactivation_indicator: Optional[StrictStr] = Field(default=None, alias="inactivationIndicator")
    association_targets: Optional[Dict[str, List[StrictStr]]] = Field(default=None, alias="associationTargets")
    module_id: Optional[Annotated[str, Field(min_length=5, strict=True, max_length=18)]] = Field(default=None, alias="moduleId")
    definition_status: Optional[StrictStr] = Field(default=None, alias="definitionStatus")
    definition_status_id: Annotated[str, Field(min_length=5, strict=True, max_length=18)] = Field(alias="definitionStatusId")
    descriptions: Optional[List[Description]] = None
    annotations: Optional[List[Annotation]] = None
    class_axioms: Optional[List[Axiom]] = Field(default=None, alias="classAxioms")
    gci_axioms: Optional[List[Axiom]] = Field(default=None, alias="gciAxioms")
    relationships: Optional[List[Relationship]] = None
    alternate_identifiers: Optional[List[Identifier]] = Field(default=None, alias="alternateIdentifiers")
    validation_results: Optional[List[InvalidContent]] = Field(default=None, alias="validationResults")
    internal_id: Optional[StrictStr] = Field(default=None, alias="internalId")
    path: Optional[StrictStr] = None
    start: Optional[datetime] = None
    end: Optional[datetime] = None
    deleted: Optional[StrictBool] = None
    changed: Optional[StrictBool] = None
    effective_time_i: Optional[StrictInt] = Field(default=None, alias="effectiveTimeI")
    release_hash: Optional[StrictStr] = Field(default=None, alias="releaseHash")
    primitive: Optional[StrictBool] = None
    active_descriptions: Optional[List[Description]] = Field(default=None, alias="activeDescriptions")
    all_owl_axiom_members: Optional[List[ReferenceSetMember]] = Field(default=None, alias="allOwlAxiomMembers")
    all_annotation_members: Optional[List[ReferenceSetMember]] = Field(default=None, alias="allAnnotationMembers")
    active_inferred_relationships: Optional[List[Relationship]] = Field(default=None, alias="activeInferredRelationships")
    __properties: ClassVar[List[str]] = ["conceptId", "descendantCount", "fsn", "pt", "active", "effectiveTime", "released", "releasedEffectiveTime", "inactivationIndicator", "associationTargets", "moduleId", "definitionStatus", "definitionStatusId", "descriptions", "annotations", "classAxioms", "gciAxioms", "relationships", "alternateIdentifiers", "validationResults", "internalId", "path", "start", "end", "deleted", "changed", "effectiveTimeI", "releaseHash", "primitive", "activeDescriptions", "allOwlAxiomMembers", "allAnnotationMembers", "activeInferredRelationships"]

    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 Concept 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 fsn
        if self.fsn:
            _dict['fsn'] = self.fsn.to_dict()
        # override the default output from pydantic by calling `to_dict()` of pt
        if self.pt:
            _dict['pt'] = self.pt.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in descriptions (list)
        _items = []
        if self.descriptions:
            for _item_descriptions in self.descriptions:
                if _item_descriptions:
                    _items.append(_item_descriptions.to_dict())
            _dict['descriptions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in annotations (list)
        _items = []
        if self.annotations:
            for _item_annotations in self.annotations:
                if _item_annotations:
                    _items.append(_item_annotations.to_dict())
            _dict['annotations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in class_axioms (list)
        _items = []
        if self.class_axioms:
            for _item_class_axioms in self.class_axioms:
                if _item_class_axioms:
                    _items.append(_item_class_axioms.to_dict())
            _dict['classAxioms'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in gci_axioms (list)
        _items = []
        if self.gci_axioms:
            for _item_gci_axioms in self.gci_axioms:
                if _item_gci_axioms:
                    _items.append(_item_gci_axioms.to_dict())
            _dict['gciAxioms'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in relationships (list)
        _items = []
        if self.relationships:
            for _item_relationships in self.relationships:
                if _item_relationships:
                    _items.append(_item_relationships.to_dict())
            _dict['relationships'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in alternate_identifiers (list)
        _items = []
        if self.alternate_identifiers:
            for _item_alternate_identifiers in self.alternate_identifiers:
                if _item_alternate_identifiers:
                    _items.append(_item_alternate_identifiers.to_dict())
            _dict['alternateIdentifiers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in validation_results (list)
        _items = []
        if self.validation_results:
            for _item_validation_results in self.validation_results:
                if _item_validation_results:
                    _items.append(_item_validation_results.to_dict())
            _dict['validationResults'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in active_descriptions (list)
        _items = []
        if self.active_descriptions:
            for _item_active_descriptions in self.active_descriptions:
                if _item_active_descriptions:
                    _items.append(_item_active_descriptions.to_dict())
            _dict['activeDescriptions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in all_owl_axiom_members (list)
        _items = []
        if self.all_owl_axiom_members:
            for _item_all_owl_axiom_members in self.all_owl_axiom_members:
                if _item_all_owl_axiom_members:
                    _items.append(_item_all_owl_axiom_members.to_dict())
            _dict['allOwlAxiomMembers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in all_annotation_members (list)
        _items = []
        if self.all_annotation_members:
            for _item_all_annotation_members in self.all_annotation_members:
                if _item_all_annotation_members:
                    _items.append(_item_all_annotation_members.to_dict())
            _dict['allAnnotationMembers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in active_inferred_relationships (list)
        _items = []
        if self.active_inferred_relationships:
            for _item_active_inferred_relationships in self.active_inferred_relationships:
                if _item_active_inferred_relationships:
                    _items.append(_item_active_inferred_relationships.to_dict())
            _dict['activeInferredRelationships'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "conceptId": obj.get("conceptId"),
            "descendantCount": obj.get("descendantCount"),
            "fsn": TermLangPojo.from_dict(obj["fsn"]) if obj.get("fsn") is not None else None,
            "pt": TermLangPojo.from_dict(obj["pt"]) if obj.get("pt") is not None else None,
            "active": obj.get("active"),
            "effectiveTime": obj.get("effectiveTime"),
            "released": obj.get("released"),
            "releasedEffectiveTime": obj.get("releasedEffectiveTime"),
            "inactivationIndicator": obj.get("inactivationIndicator"),
            "associationTargets": obj.get("associationTargets"),
            "moduleId": obj.get("moduleId"),
            "definitionStatus": obj.get("definitionStatus"),
            "definitionStatusId": obj.get("definitionStatusId"),
            "descriptions": [Description.from_dict(_item) for _item in obj["descriptions"]] if obj.get("descriptions") is not None else None,
            "annotations": [Annotation.from_dict(_item) for _item in obj["annotations"]] if obj.get("annotations") is not None else None,
            "classAxioms": [Axiom.from_dict(_item) for _item in obj["classAxioms"]] if obj.get("classAxioms") is not None else None,
            "gciAxioms": [Axiom.from_dict(_item) for _item in obj["gciAxioms"]] if obj.get("gciAxioms") is not None else None,
            "relationships": [Relationship.from_dict(_item) for _item in obj["relationships"]] if obj.get("relationships") is not None else None,
            "alternateIdentifiers": [Identifier.from_dict(_item) for _item in obj["alternateIdentifiers"]] if obj.get("alternateIdentifiers") is not None else None,
            "validationResults": [InvalidContent.from_dict(_item) for _item in obj["validationResults"]] if obj.get("validationResults") is not None else None,
            "internalId": obj.get("internalId"),
            "path": obj.get("path"),
            "start": obj.get("start"),
            "end": obj.get("end"),
            "deleted": obj.get("deleted"),
            "changed": obj.get("changed"),
            "effectiveTimeI": obj.get("effectiveTimeI"),
            "releaseHash": obj.get("releaseHash"),
            "primitive": obj.get("primitive"),
            "activeDescriptions": [Description.from_dict(_item) for _item in obj["activeDescriptions"]] if obj.get("activeDescriptions") is not None else None,
            "allOwlAxiomMembers": [ReferenceSetMember.from_dict(_item) for _item in obj["allOwlAxiomMembers"]] if obj.get("allOwlAxiomMembers") is not None else None,
            "allAnnotationMembers": [ReferenceSetMember.from_dict(_item) for _item in obj["allAnnotationMembers"]] if obj.get("allAnnotationMembers") is not None else None,
            "activeInferredRelationships": [Relationship.from_dict(_item) for _item in obj["activeInferredRelationships"]] if obj.get("activeInferredRelationships") is not None else None
        })
        return _obj


