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


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

    item_codeable_concept: CodeableConcept | None = Field(
        None, alias="itemCodeableConcept", serialization_alias="itemCodeableConcept"
    )
    item_reference: Reference | None = Field(
        None, alias="itemReference", serialization_alias="itemReference"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )


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

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

    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    destination: Reference | None = Field(
        None, alias="destination", serialization_alias="destination"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    occurrence_date_time: str | None = Field(
        None, alias="occurrenceDateTime", serialization_alias="occurrenceDateTime"
    )
    occurrence_period: Period | None = Field(
        None, alias="occurrencePeriod", serialization_alias="occurrencePeriod"
    )
    occurrence_timing: Timing | None = Field(
        None, alias="occurrenceTiming", serialization_alias="occurrenceTiming"
    )
    part_of: PyList[Reference] | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    patient: Reference | None = Field(
        None, alias="patient", serialization_alias="patient"
    )
    receiver: PyList[Reference] | None = Field(
        None, alias="receiver", serialization_alias="receiver"
    )
    status: (
        Literal["in-progress", "completed", "abandoned", "entered-in-error"] | None
    ) = Field(None, alias="status", serialization_alias="status")
    supplied_item: SupplyDeliverySuppliedItem | None = Field(
        None, alias="suppliedItem", serialization_alias="suppliedItem"
    )
    supplier: Reference | None = Field(
        None, alias="supplier", serialization_alias="supplier"
    )
    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) -> SupplyDelivery:
        return cls.model_validate_json(json)
