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


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    confidentiality: CodeableConcept | None = Field(
        None, alias="confidentiality", serialization_alias="confidentiality"
    )
    group: CodeableConcept = Field(alias="group", serialization_alias="group")
    strength: PyList[MedicinalProductIngredientSpecifiedSubstanceStrength] | None = (
        Field(None, alias="strength", serialization_alias="strength")
    )


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

    concentration: Ratio | None = Field(
        None, alias="concentration", serialization_alias="concentration"
    )
    concentration_low_limit: Ratio | None = Field(
        None, alias="concentrationLowLimit", serialization_alias="concentrationLowLimit"
    )
    country: PyList[CodeableConcept] | None = Field(
        None, alias="country", serialization_alias="country"
    )
    measurement_point: str | None = Field(
        None, alias="measurementPoint", serialization_alias="measurementPoint"
    )
    presentation: Ratio = Field(
        alias="presentation", serialization_alias="presentation"
    )
    presentation_low_limit: Ratio | None = Field(
        None, alias="presentationLowLimit", serialization_alias="presentationLowLimit"
    )
    reference_strength: (
        PyList[MedicinalProductIngredientSpecifiedSubstanceStrengthReferenceStrength]
        | None
    ) = Field(None, alias="referenceStrength", serialization_alias="referenceStrength")


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

    country: PyList[CodeableConcept] | None = Field(
        None, alias="country", serialization_alias="country"
    )
    measurement_point: str | None = Field(
        None, alias="measurementPoint", serialization_alias="measurementPoint"
    )
    strength: Ratio = Field(alias="strength", serialization_alias="strength")
    strength_low_limit: Ratio | None = Field(
        None, alias="strengthLowLimit", serialization_alias="strengthLowLimit"
    )
    substance: CodeableConcept | None = Field(
        None, alias="substance", serialization_alias="substance"
    )


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

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


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

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

    allergenic_indicator: bool | None = Field(
        None, alias="allergenicIndicator", serialization_alias="allergenicIndicator"
    )
    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    manufacturer: PyList[Reference] | None = Field(
        None, alias="manufacturer", serialization_alias="manufacturer"
    )
    role: CodeableConcept = Field(alias="role", serialization_alias="role")
    specified_substance: PyList[MedicinalProductIngredientSpecifiedSubstance] | None = (
        Field(
            None, alias="specifiedSubstance", serialization_alias="specifiedSubstance"
        )
    )
    substance: MedicinalProductIngredientSubstance | None = Field(
        None, alias="substance", serialization_alias="substance"
    )

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