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


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    status: CodeableConcept | None = Field(
        None, alias="status", serialization_alias="status"
    )


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    first_dose: Quantity | None = Field(
        None, alias="firstDose", serialization_alias="firstDose"
    )
    max_dose_per_day: Quantity | None = Field(
        None, alias="maxDosePerDay", serialization_alias="maxDosePerDay"
    )
    max_dose_per_treatment_period: Ratio | None = Field(
        None,
        alias="maxDosePerTreatmentPeriod",
        serialization_alias="maxDosePerTreatmentPeriod",
    )
    max_single_dose: Quantity | None = Field(
        None, alias="maxSingleDose", serialization_alias="maxSingleDose"
    )
    max_treatment_period: Duration | None = Field(
        None, alias="maxTreatmentPeriod", serialization_alias="maxTreatmentPeriod"
    )
    target_species: (
        PyList[MedicinalProductPharmaceuticalRouteOfAdministrationTargetSpecies] | None
    ) = Field(None, alias="targetSpecies", serialization_alias="targetSpecies")


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    withdrawal_period: (
        PyList[
            MedicinalProductPharmaceuticalRouteOfAdministrationTargetSpeciesWithdrawalPeriod
        ]
        | None
    ) = Field(None, alias="withdrawalPeriod", serialization_alias="withdrawalPeriod")


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

    supporting_information: str | None = Field(
        None, alias="supportingInformation", serialization_alias="supportingInformation"
    )
    tissue: CodeableConcept = Field(alias="tissue", serialization_alias="tissue")
    value: Quantity = Field(alias="value", serialization_alias="value")


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

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

    administrable_dose_form: CodeableConcept = Field(
        alias="administrableDoseForm", serialization_alias="administrableDoseForm"
    )
    characteristics: PyList[MedicinalProductPharmaceuticalCharacteristics] | None = (
        Field(None, alias="characteristics", serialization_alias="characteristics")
    )
    device: PyList[Reference] | None = Field(
        None, alias="device", serialization_alias="device"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    ingredient: PyList[Reference] | None = Field(
        None, alias="ingredient", serialization_alias="ingredient"
    )
    route_of_administration: PyList[
        MedicinalProductPharmaceuticalRouteOfAdministration
    ] = Field(
        alias="routeOfAdministration", serialization_alias="routeOfAdministration"
    )
    unit_of_presentation: CodeableConcept | None = Field(
        None, alias="unitOfPresentation", serialization_alias="unitOfPresentation"
    )

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