# 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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from snowstorm_client.models.concept_mini import ConceptMini
from typing import Optional, Set
from typing_extensions import Self

class RelationshipChange(BaseModel):
    """
    RelationshipChange
    """ # noqa: E501
    internal_id: Optional[StrictStr] = Field(default=None, alias="internalId")
    classification_id: Optional[StrictStr] = Field(default=None, alias="classificationId")
    relationship_id: Optional[StrictStr] = Field(default=None, alias="relationshipId")
    active: Optional[StrictBool] = None
    source_id: Optional[StrictStr] = Field(default=None, alias="sourceId")
    destination_id: Optional[StrictStr] = Field(default=None, alias="destinationId")
    value: Optional[StrictStr] = None
    group: Optional[StrictInt] = None
    type_id: Optional[StrictStr] = Field(default=None, alias="typeId")
    modifier_id: Optional[StrictStr] = Field(default=None, alias="modifierId")
    inferred_not_stated: Optional[StrictBool] = Field(default=None, alias="inferredNotStated")
    source: Optional[ConceptMini] = None
    destination: Optional[ConceptMini] = None
    type: Optional[ConceptMini] = None
    concrete: Optional[StrictBool] = None
    change_nature: Optional[StrictStr] = Field(default=None, alias="changeNature")
    destination_or_value: Optional[StrictStr] = Field(default=None, alias="destinationOrValue")
    characteristic_type_id: Optional[StrictStr] = Field(default=None, alias="characteristicTypeId")
    destination_or_value_without_prefix: Optional[StrictStr] = Field(default=None, alias="destinationOrValueWithoutPrefix")
    destination_or_raw_value: Optional[Dict[str, Any]] = Field(default=None, alias="destinationOrRawValue")
    source_fsn: Optional[StrictStr] = Field(default=None, alias="sourceFsn")
    type_fsn: Optional[StrictStr] = Field(default=None, alias="typeFsn")
    destination_fsn: Optional[StrictStr] = Field(default=None, alias="destinationFsn")
    union_group: Optional[StrictInt] = Field(default=None, alias="unionGroup")
    __properties: ClassVar[List[str]] = ["internalId", "classificationId", "relationshipId", "active", "sourceId", "destinationId", "value", "group", "typeId", "modifierId", "inferredNotStated", "source", "destination", "type", "concrete", "changeNature", "destinationOrValue", "characteristicTypeId", "destinationOrValueWithoutPrefix", "destinationOrRawValue", "sourceFsn", "typeFsn", "destinationFsn", "unionGroup"]

    @field_validator('change_nature')
    def change_nature_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['INFERRED', 'REDUNDANT']):
            raise ValueError("must be one of enum values ('INFERRED', 'REDUNDANT')")
        return value

    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 RelationshipChange 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 source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of destination
        if self.destination:
            _dict['destination'] = self.destination.to_dict()
        # override the default output from pydantic by calling `to_dict()` of type
        if self.type:
            _dict['type'] = self.type.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "internalId": obj.get("internalId"),
            "classificationId": obj.get("classificationId"),
            "relationshipId": obj.get("relationshipId"),
            "active": obj.get("active"),
            "sourceId": obj.get("sourceId"),
            "destinationId": obj.get("destinationId"),
            "value": obj.get("value"),
            "group": obj.get("group"),
            "typeId": obj.get("typeId"),
            "modifierId": obj.get("modifierId"),
            "inferredNotStated": obj.get("inferredNotStated"),
            "source": ConceptMini.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "destination": ConceptMini.from_dict(obj["destination"]) if obj.get("destination") is not None else None,
            "type": ConceptMini.from_dict(obj["type"]) if obj.get("type") is not None else None,
            "concrete": obj.get("concrete"),
            "changeNature": obj.get("changeNature"),
            "destinationOrValue": obj.get("destinationOrValue"),
            "characteristicTypeId": obj.get("characteristicTypeId"),
            "destinationOrValueWithoutPrefix": obj.get("destinationOrValueWithoutPrefix"),
            "destinationOrRawValue": obj.get("destinationOrRawValue"),
            "sourceFsn": obj.get("sourceFsn"),
            "typeFsn": obj.get("typeFsn"),
            "destinationFsn": obj.get("destinationFsn"),
            "unionGroup": obj.get("unionGroup")
        })
        return _obj


