# 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,
    MarketingStatus,
    ProdCharacteristic,
    ProductShelfLife,
    Quantity,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    immediate_packaging: Identifier | None = Field(
        None, alias="immediatePackaging", serialization_alias="immediatePackaging"
    )
    outer_packaging: Identifier = Field(
        alias="outerPackaging", serialization_alias="outerPackaging"
    )


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

    alternate_material: PyList[CodeableConcept] | None = Field(
        None, alias="alternateMaterial", serialization_alias="alternateMaterial"
    )
    device: PyList[Reference] | None = Field(
        None, alias="device", serialization_alias="device"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    manufactured_item: PyList[Reference] | None = Field(
        None, alias="manufacturedItem", serialization_alias="manufacturedItem"
    )
    manufacturer: PyList[Reference] | None = Field(
        None, alias="manufacturer", serialization_alias="manufacturer"
    )
    material: PyList[CodeableConcept] | None = Field(
        None, alias="material", serialization_alias="material"
    )
    other_characteristics: PyList[CodeableConcept] | None = Field(
        None, alias="otherCharacteristics", serialization_alias="otherCharacteristics"
    )
    package_item: PyList[MedicinalProductPackagedPackageItem] | None = Field(
        None, alias="packageItem", serialization_alias="packageItem"
    )
    physical_characteristics: ProdCharacteristic | None = Field(
        None,
        alias="physicalCharacteristics",
        serialization_alias="physicalCharacteristics",
    )
    quantity: Quantity = Field(alias="quantity", serialization_alias="quantity")
    shelf_life_storage: PyList[ProductShelfLife] | None = Field(
        None, alias="shelfLifeStorage", serialization_alias="shelfLifeStorage"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

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

    batch_identifier: PyList[MedicinalProductPackagedBatchIdentifier] | None = Field(
        None, alias="batchIdentifier", serialization_alias="batchIdentifier"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    legal_status_of_supply: CodeableConcept | None = Field(
        None, alias="legalStatusOfSupply", serialization_alias="legalStatusOfSupply"
    )
    manufacturer: PyList[Reference] | None = Field(
        None, alias="manufacturer", serialization_alias="manufacturer"
    )
    marketing_authorization: Reference | None = Field(
        None,
        alias="marketingAuthorization",
        serialization_alias="marketingAuthorization",
    )
    marketing_status: PyList[MarketingStatus] | None = Field(
        None, alias="marketingStatus", serialization_alias="marketingStatus"
    )
    package_item: PyList[MedicinalProductPackagedPackageItem] = Field(
        alias="packageItem", serialization_alias="packageItem"
    )
    subject: PyList[Reference] | None = Field(
        None, 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) -> MedicinalProductPackaged:
        return cls.model_validate_json(json)
