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


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

    authorisation_reference_number: Identifier | None = Field(
        None,
        alias="authorisationReferenceNumber",
        serialization_alias="authorisationReferenceNumber",
    )
    confidentiality_indicator: CodeableConcept | None = Field(
        None,
        alias="confidentialityIndicator",
        serialization_alias="confidentialityIndicator",
    )
    effective_date: str | None = Field(
        None, alias="effectiveDate", serialization_alias="effectiveDate"
    )
    manufacturer: PyList[Reference] | None = Field(
        None, alias="manufacturer", serialization_alias="manufacturer"
    )
    operation_type: CodeableConcept | None = Field(
        None, alias="operationType", serialization_alias="operationType"
    )
    regulator: Reference | None = Field(
        None, alias="regulator", serialization_alias="regulator"
    )


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

    country_language: PyList[MedicinalProductNameCountryLanguage] | None = Field(
        None, alias="countryLanguage", serialization_alias="countryLanguage"
    )
    name_part: PyList[MedicinalProductNameNamePart] | None = Field(
        None, alias="namePart", serialization_alias="namePart"
    )
    product_name: str = Field(alias="productName", serialization_alias="productName")


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

    country: CodeableConcept = Field(alias="country", serialization_alias="country")
    jurisdiction: CodeableConcept | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    language: CodeableConcept = Field(alias="language", serialization_alias="language")


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

    part: str = Field(alias="part", serialization_alias="part")
    type: Coding = Field(alias="type", serialization_alias="type")


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

    date: str | None = Field(None, alias="date", serialization_alias="date")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    indication_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="indicationCodeableConcept",
        serialization_alias="indicationCodeableConcept",
    )
    indication_reference: Reference | None = Field(
        None, alias="indicationReference", serialization_alias="indicationReference"
    )
    intended_use: CodeableConcept | None = Field(
        None, alias="intendedUse", serialization_alias="intendedUse"
    )
    species: CodeableConcept | None = Field(
        None, alias="species", serialization_alias="species"
    )
    status: CodeableConcept | None = Field(
        None, alias="status", serialization_alias="status"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

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

    additional_monitoring_indicator: CodeableConcept | None = Field(
        None,
        alias="additionalMonitoringIndicator",
        serialization_alias="additionalMonitoringIndicator",
    )
    attached_document: PyList[Reference] | None = Field(
        None, alias="attachedDocument", serialization_alias="attachedDocument"
    )
    clinical_trial: PyList[Reference] | None = Field(
        None, alias="clinicalTrial", serialization_alias="clinicalTrial"
    )
    combined_pharmaceutical_dose_form: CodeableConcept | None = Field(
        None,
        alias="combinedPharmaceuticalDoseForm",
        serialization_alias="combinedPharmaceuticalDoseForm",
    )
    contact: PyList[Reference] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    cross_reference: PyList[Identifier] | None = Field(
        None, alias="crossReference", serialization_alias="crossReference"
    )
    domain: Coding | None = Field(None, alias="domain", serialization_alias="domain")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    legal_status_of_supply: CodeableConcept | None = Field(
        None, alias="legalStatusOfSupply", serialization_alias="legalStatusOfSupply"
    )
    manufacturing_business_operation: (
        PyList[MedicinalProductManufacturingBusinessOperation] | None
    ) = Field(
        None,
        alias="manufacturingBusinessOperation",
        serialization_alias="manufacturingBusinessOperation",
    )
    marketing_status: PyList[MarketingStatus] | None = Field(
        None, alias="marketingStatus", serialization_alias="marketingStatus"
    )
    master_file: PyList[Reference] | None = Field(
        None, alias="masterFile", serialization_alias="masterFile"
    )
    name: PyList[MedicinalProductName] = Field(alias="name", serialization_alias="name")
    packaged_medicinal_product: PyList[Reference] | None = Field(
        None,
        alias="packagedMedicinalProduct",
        serialization_alias="packagedMedicinalProduct",
    )
    paediatric_use_indicator: CodeableConcept | None = Field(
        None,
        alias="paediatricUseIndicator",
        serialization_alias="paediatricUseIndicator",
    )
    pharmaceutical_product: PyList[Reference] | None = Field(
        None, alias="pharmaceuticalProduct", serialization_alias="pharmaceuticalProduct"
    )
    product_classification: PyList[CodeableConcept] | None = Field(
        None, alias="productClassification", serialization_alias="productClassification"
    )
    special_designation: PyList[MedicinalProductSpecialDesignation] | None = Field(
        None, alias="specialDesignation", serialization_alias="specialDesignation"
    )
    special_measures: PyList[str] | None = Field(
        None, alias="specialMeasures", serialization_alias="specialMeasures"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")

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