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


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

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

    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    category: CodeableConcept | None = Field(
        None, alias="category", serialization_alias="category"
    )
    context: Reference | None = Field(
        None, alias="context", serialization_alias="context"
    )
    date_asserted: str | None = Field(
        None, alias="dateAsserted", serialization_alias="dateAsserted"
    )
    derived_from: PyList[Reference] | None = Field(
        None, alias="derivedFrom", serialization_alias="derivedFrom"
    )
    dosage: PyList[Dosage] | None = Field(
        None, alias="dosage", serialization_alias="dosage"
    )
    effective_date_time: str | None = Field(
        None, alias="effectiveDateTime", serialization_alias="effectiveDateTime"
    )
    effective_period: Period | None = Field(
        None, alias="effectivePeriod", serialization_alias="effectivePeriod"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    information_source: Reference | None = Field(
        None, alias="informationSource", serialization_alias="informationSource"
    )
    medication_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="medicationCodeableConcept",
        serialization_alias="medicationCodeableConcept",
    )
    medication_reference: Reference | None = Field(
        None, alias="medicationReference", serialization_alias="medicationReference"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    part_of: PyList[Reference] | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    status: Literal[
        "active",
        "completed",
        "entered-in-error",
        "intended",
        "stopped",
        "on-hold",
        "unknown",
        "not-taken",
    ] = Field(alias="status", serialization_alias="status")
    status_reason: PyList[CodeableConcept] | None = Field(
        None, alias="statusReason", serialization_alias="statusReason"
    )
    subject: Reference = Field(alias="subject", serialization_alias="subject")

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