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


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

    content_attachment: Attachment | None = Field(
        None, alias="contentAttachment", serialization_alias="contentAttachment"
    )
    content_reference: Reference | None = Field(
        None, alias="contentReference", serialization_alias="contentReference"
    )
    content_string: str | None = Field(
        None, alias="contentString", serialization_alias="contentString"
    )


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

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

    about: PyList[Reference] | None = Field(
        None, alias="about", serialization_alias="about"
    )
    authored_on: str | None = Field(
        None, alias="authoredOn", serialization_alias="authoredOn"
    )
    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    do_not_perform: bool | None = Field(
        None, alias="doNotPerform", serialization_alias="doNotPerform"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    group_identifier: Identifier | None = Field(
        None, alias="groupIdentifier", serialization_alias="groupIdentifier"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    medium: PyList[CodeableConcept] | None = Field(
        None, alias="medium", serialization_alias="medium"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    occurrence_date_time: str | None = Field(
        None, alias="occurrenceDateTime", serialization_alias="occurrenceDateTime"
    )
    occurrence_period: Period | None = Field(
        None, alias="occurrencePeriod", serialization_alias="occurrencePeriod"
    )
    payload: PyList[CommunicationRequestPayload] | None = Field(
        None, alias="payload", serialization_alias="payload"
    )
    priority: Literal["routine", "urgent", "asap", "stat"] | None = Field(
        None, alias="priority", serialization_alias="priority"
    )
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    recipient: PyList[Reference] | None = Field(
        None, alias="recipient", serialization_alias="recipient"
    )
    replaces: PyList[Reference] | None = Field(
        None, alias="replaces", serialization_alias="replaces"
    )
    requester: Reference | None = Field(
        None, alias="requester", serialization_alias="requester"
    )
    sender: Reference | None = Field(None, alias="sender", serialization_alias="sender")
    status: Literal[
        "draft",
        "active",
        "on-hold",
        "revoked",
        "completed",
        "entered-in-error",
        "unknown",
    ] = Field(alias="status", serialization_alias="status")
    status_reason: CodeableConcept | None = Field(
        None, alias="statusReason", serialization_alias="statusReason"
    )
    subject: 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) -> CommunicationRequest:
        return cls.model_validate_json(json)
