# 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

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


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

    code: PyList[CodeableConcept] | None = Field(
        None, alias="code", serialization_alias="code"
    )
    detail: PyList[Reference] | None = Field(
        None, alias="detail", serialization_alias="detail"
    )


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

    assessment: PyList[Reference] | None = Field(
        None, alias="assessment", serialization_alias="assessment"
    )
    summary: CodeableConcept | None = Field(
        None, alias="summary", serialization_alias="summary"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

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

    abatement_age: Age | None = Field(
        None, alias="abatementAge", serialization_alias="abatementAge"
    )
    abatement_date_time: str | None = Field(
        None, alias="abatementDateTime", serialization_alias="abatementDateTime"
    )
    abatement_period: Period | None = Field(
        None, alias="abatementPeriod", serialization_alias="abatementPeriod"
    )
    abatement_range: Range | None = Field(
        None, alias="abatementRange", serialization_alias="abatementRange"
    )
    abatement_string: str | None = Field(
        None, alias="abatementString", serialization_alias="abatementString"
    )
    asserter: Reference | None = Field(
        None, alias="asserter", serialization_alias="asserter"
    )
    body_site: PyList[CodeableConcept] | None = Field(
        None, alias="bodySite", serialization_alias="bodySite"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    clinical_status: CodeableConcept | None = Field(
        None, alias="clinicalStatus", serialization_alias="clinicalStatus"
    )
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    evidence: PyList[ConditionEvidence] | None = Field(
        None, alias="evidence", serialization_alias="evidence"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    onset_age: Age | None = Field(
        None, alias="onsetAge", serialization_alias="onsetAge"
    )
    onset_date_time: str | None = Field(
        None, alias="onsetDateTime", serialization_alias="onsetDateTime"
    )
    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"
    )
    recorded_date: str | None = Field(
        None, alias="recordedDate", serialization_alias="recordedDate"
    )
    recorder: Reference | None = Field(
        None, alias="recorder", serialization_alias="recorder"
    )
    severity: CodeableConcept | None = Field(
        None, alias="severity", serialization_alias="severity"
    )
    stage: PyList[ConditionStage] | None = Field(
        None, alias="stage", serialization_alias="stage"
    )
    subject: Reference = Field(alias="subject", serialization_alias="subject")
    verification_status: CodeableConcept | None = Field(
        None, alias="verificationStatus", serialization_alias="verificationStatus"
    )

    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) -> Condition:
        return cls.model_validate_json(json)
