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


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

    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_codeable_concept: CodeableConcept | None = Field(
        None, alias="valueCodeableConcept", serialization_alias="valueCodeableConcept"
    )
    value_quantity: Quantity | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )
    value_range: Range | None = Field(
        None, alias="valueRange", serialization_alias="valueRange"
    )


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

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

    authored_on: str | None = Field(
        None, alias="authoredOn", serialization_alias="authoredOn"
    )
    category: CodeableConcept | None = Field(
        None, alias="category", serialization_alias="category"
    )
    deliver_from: Reference | None = Field(
        None, alias="deliverFrom", serialization_alias="deliverFrom"
    )
    deliver_to: Reference | None = Field(
        None, alias="deliverTo", serialization_alias="deliverTo"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    item_codeable_concept: CodeableConcept | None = Field(
        None, alias="itemCodeableConcept", serialization_alias="itemCodeableConcept"
    )
    item_reference: Reference | None = Field(
        None, alias="itemReference", serialization_alias="itemReference"
    )
    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"
    )
    parameter: PyList[SupplyRequestParameter] | None = Field(
        None, alias="parameter", serialization_alias="parameter"
    )
    priority: Literal["routine", "urgent", "asap", "stat"] | None = Field(
        None, alias="priority", serialization_alias="priority"
    )
    quantity: Quantity = Field(alias="quantity", serialization_alias="quantity")
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    requester: Reference | None = Field(
        None, alias="requester", serialization_alias="requester"
    )
    status: (
        Literal[
            "draft",
            "active",
            "suspended",
            "cancelled",
            "completed",
            "entered-in-error",
            "unknown",
        ]
        | None
    ) = Field(None, alias="status", serialization_alias="status")
    supplier: PyList[Reference] | None = Field(
        None, alias="supplier", serialization_alias="supplier"
    )

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