# 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 (
    BackboneElement,
    CodeableConcept,
    Identifier,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    causality: PyList[AdverseEventSuspectEntityCausality] | None = Field(
        None, alias="causality", serialization_alias="causality"
    )
    instance: Reference = Field(alias="instance", serialization_alias="instance")


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

    assessment: CodeableConcept | None = Field(
        None, alias="assessment", serialization_alias="assessment"
    )
    author: Reference | None = Field(None, alias="author", serialization_alias="author")
    method: CodeableConcept | None = Field(
        None, alias="method", serialization_alias="method"
    )
    product_relatedness: str | None = Field(
        None, alias="productRelatedness", serialization_alias="productRelatedness"
    )


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

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

    actuality: Literal["actual", "potential"] = Field(
        alias="actuality", serialization_alias="actuality"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    contributor: PyList[Reference] | None = Field(
        None, alias="contributor", serialization_alias="contributor"
    )
    date: str | None = Field(None, alias="date", serialization_alias="date")
    detected: str | None = Field(None, alias="detected", serialization_alias="detected")
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    event: CodeableConcept | None = Field(
        None, alias="event", serialization_alias="event"
    )
    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    location: Reference | None = Field(
        None, alias="location", serialization_alias="location"
    )
    outcome: CodeableConcept | None = Field(
        None, alias="outcome", serialization_alias="outcome"
    )
    recorded_date: str | None = Field(
        None, alias="recordedDate", serialization_alias="recordedDate"
    )
    recorder: Reference | None = Field(
        None, alias="recorder", serialization_alias="recorder"
    )
    reference_document: PyList[Reference] | None = Field(
        None, alias="referenceDocument", serialization_alias="referenceDocument"
    )
    resulting_condition: PyList[Reference] | None = Field(
        None, alias="resultingCondition", serialization_alias="resultingCondition"
    )
    seriousness: CodeableConcept | None = Field(
        None, alias="seriousness", serialization_alias="seriousness"
    )
    severity: CodeableConcept | None = Field(
        None, alias="severity", serialization_alias="severity"
    )
    study: PyList[Reference] | None = Field(
        None, alias="study", serialization_alias="study"
    )
    subject: Reference = Field(alias="subject", serialization_alias="subject")
    subject_medical_history: PyList[Reference] | None = Field(
        None, alias="subjectMedicalHistory", serialization_alias="subjectMedicalHistory"
    )
    suspect_entity: PyList[AdverseEventSuspectEntity] | None = Field(
        None, alias="suspectEntity", serialization_alias="suspectEntity"
    )

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