# WARNING: This file is autogenerated by FHIR Schema Codegen.
# https://github.com/fhir-schema/fhir-schema-codegen
# Any manual changes made to this file may be overwritten.

from __future__ import annotations
from pydantic import ConfigDict, Field
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    Age,
    Annotation,
    BackboneElement,
    CodeableConcept,
    Identifier,
    Period,
    Range,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


class FamilyMemberHistoryCondition(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    contributed_to_death: bool | None = Field(
        None, alias="contributedToDeath", serialization_alias="contributedToDeath"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    onset_age: Age | None = Field(
        None, alias="onsetAge", serialization_alias="onsetAge"
    )
    onset_period: Period | None = Field(
        None, alias="onsetPeriod", serialization_alias="onsetPeriod"
    )
    onset_range: Range | None = Field(
        None, alias="onsetRange", serialization_alias="onsetRange"
    )
    onset_string: str | None = Field(
        None, alias="onsetString", serialization_alias="onsetString"
    )
    outcome: CodeableConcept | None = Field(
        None, alias="outcome", serialization_alias="outcome"
    )


class FamilyMemberHistory(DomainResource):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    resource_type: str = Field(
        default="FamilyMemberHistory",
        alias="resourceType",
        serialization_alias="resourceType",
        frozen=True,
        pattern="FamilyMemberHistory",
    )

    age_age: Age | None = Field(None, alias="ageAge", serialization_alias="ageAge")
    age_range: Range | None = Field(
        None, alias="ageRange", serialization_alias="ageRange"
    )
    age_string: str | None = Field(
        None, alias="ageString", serialization_alias="ageString"
    )
    born_date: str | None = Field(
        None, alias="bornDate", serialization_alias="bornDate"
    )
    born_period: Period | None = Field(
        None, alias="bornPeriod", serialization_alias="bornPeriod"
    )
    born_string: str | None = Field(
        None, alias="bornString", serialization_alias="bornString"
    )
    condition: PyList[FamilyMemberHistoryCondition] | None = Field(
        None, alias="condition", serialization_alias="condition"
    )
    data_absent_reason: CodeableConcept | None = Field(
        None, alias="dataAbsentReason", serialization_alias="dataAbsentReason"
    )
    date: str | None = Field(None, alias="date", serialization_alias="date")
    deceased_age: Age | None = Field(
        None, alias="deceasedAge", serialization_alias="deceasedAge"
    )
    deceased_boolean: bool | None = Field(
        None, alias="deceasedBoolean", serialization_alias="deceasedBoolean"
    )
    deceased_date: str | None = Field(
        None, alias="deceasedDate", serialization_alias="deceasedDate"
    )
    deceased_range: Range | None = Field(
        None, alias="deceasedRange", serialization_alias="deceasedRange"
    )
    deceased_string: str | None = Field(
        None, alias="deceasedString", serialization_alias="deceasedString"
    )
    estimated_age: bool | None = Field(
        None, alias="estimatedAge", serialization_alias="estimatedAge"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    instantiates_canonical: PyList[str] | None = Field(
        None, alias="instantiatesCanonical", serialization_alias="instantiatesCanonical"
    )
    instantiates_uri: PyList[str] | None = Field(
        None, alias="instantiatesUri", serialization_alias="instantiatesUri"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    patient: Reference = Field(alias="patient", serialization_alias="patient")
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    relationship: CodeableConcept = Field(
        alias="relationship", serialization_alias="relationship"
    )
    sex: CodeableConcept | None = Field(None, alias="sex", serialization_alias="sex")
    status: Literal["partial", "completed", "entered-in-error", "health-unknown"] = (
        Field(alias="status", serialization_alias="status")
    )

    def to_json(self, indent: int | None = None) -> str:
        return self.model_dump_json(
            exclude_unset=True, exclude_none=True, indent=indent
        )

    @classmethod
    def from_json(cls, json: str) -> FamilyMemberHistory:
        return cls.model_validate_json(json)
