# coding: utf-8

"""
    UniCourt Enterprise APIs

    <button><a href=\"/developers/enterpriseapi/api/download/UniCourt-Enterprise-API-Spec.yaml\" >Download UniCourt Enterprise APIs Specification</a></button> 

    The version of the OpenAPI document: 
    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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from unicourt.model.case_relationship_type import CaseRelationshipType
from unicourt.model.source_structured_data import SourceStructuredData
from typing import Optional, Set
from typing_extensions import Self

class RelatedCase(BaseModel):
    """
    RelatedCase
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=11, strict=True, max_length=11)]] = Field(default='RelatedCase', description="Name of the object")
    case_id: Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]] = Field(default=None, description="Case ID of the related Case. This can be null if this case in not found in our database. However the meta information of the related case will be present.", alias="caseId")
    case_number: Optional[Annotated[str, Field(min_length=3, strict=True, max_length=50)]] = Field(default=None, description="Case Number of the related Case.", alias="caseNumber")
    case_name: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, description="Case Name of the related Case.", alias="caseName")
    case_relationship_type: Optional[CaseRelationshipType] = Field(default=None, alias="caseRelationshipType")
    source_case_relationship_type: Optional[Annotated[str, Field(min_length=3, strict=True, max_length=250)]] = Field(default=None, description="Case Relationship Type provided by court.", alias="sourceCaseRelationshipType")
    is_visible: Optional[StrictBool] = Field(default=None, description="This specifies if the related cases is still related to the parent case or not.", alias="isVisible")
    additional_source_data: Optional[SourceStructuredData] = Field(default=None, alias="additionalSourceData")
    case_api: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Link to the Case API of the current related case.", alias="caseAPI")
    __properties: ClassVar[List[str]] = ["object", "caseId", "caseNumber", "caseName", "caseRelationshipType", "sourceCaseRelationshipType", "isVisible", "additionalSourceData", "caseAPI"]

    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 RelatedCase 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 case_relationship_type
        if self.case_relationship_type:
            _dict['caseRelationshipType'] = self.case_relationship_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of additional_source_data
        if self.additional_source_data:
            _dict['additionalSourceData'] = self.additional_source_data.to_dict()
        # set to None if case_id (nullable) is None
        # and model_fields_set contains the field
        if self.case_id is None and "case_id" in self.model_fields_set:
            _dict['caseId'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "object": obj.get("object") if obj.get("object") is not None else 'RelatedCase',
            "caseId": obj.get("caseId"),
            "caseNumber": obj.get("caseNumber"),
            "caseName": obj.get("caseName"),
            "caseRelationshipType": CaseRelationshipType.from_dict(obj["caseRelationshipType"]) if obj.get("caseRelationshipType") is not None else None,
            "sourceCaseRelationshipType": obj.get("sourceCaseRelationshipType"),
            "isVisible": obj.get("isVisible"),
            "additionalSourceData": SourceStructuredData.from_dict(obj["additionalSourceData"]) if obj.get("additionalSourceData") is not None else None,
            "caseAPI": obj.get("caseAPI")
        })
        return _obj


