# 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,
    Period,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


class DetectedIssueEvidence(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 DetectedIssueMitigation(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    action: CodeableConcept = Field(alias="action", serialization_alias="action")
    author: Reference | None = Field(None, alias="author", serialization_alias="author")
    date: str | None = Field(None, alias="date", serialization_alias="date")


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

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

    author: Reference | None = Field(None, alias="author", serialization_alias="author")
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    detail: str | None = Field(None, alias="detail", serialization_alias="detail")
    evidence: PyList[DetectedIssueEvidence] | None = Field(
        None, alias="evidence", serialization_alias="evidence"
    )
    identified_date_time: str | None = Field(
        None, alias="identifiedDateTime", serialization_alias="identifiedDateTime"
    )
    identified_period: Period | None = Field(
        None, alias="identifiedPeriod", serialization_alias="identifiedPeriod"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    implicated: PyList[Reference] | None = Field(
        None, alias="implicated", serialization_alias="implicated"
    )
    mitigation: PyList[DetectedIssueMitigation] | None = Field(
        None, alias="mitigation", serialization_alias="mitigation"
    )
    patient: Reference | None = Field(
        None, alias="patient", serialization_alias="patient"
    )
    reference: str | None = Field(
        None, alias="reference", serialization_alias="reference"
    )
    severity: Literal["high", "moderate", "low"] | None = Field(
        None, alias="severity", serialization_alias="severity"
    )
    status: Literal[
        "registered",
        "preliminary",
        "final",
        "amended",
        "cancelled",
        "entered-in-error",
        "unknown",
        "corrected",
    ] = 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) -> DetectedIssue:
        return cls.model_validate_json(json)
