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


class CommunicationPayload(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 Communication(DomainResource):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

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

    about: PyList[Reference] | None = Field(
        None, alias="about", serialization_alias="about"
    )
    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    in_response_to: PyList[Reference] | None = Field(
        None, alias="inResponseTo", serialization_alias="inResponseTo"
    )
    instantiates_canonical: PyList[str] | None = Field(
        None, alias="instantiatesCanonical", serialization_alias="instantiatesCanonical"
    )
    instantiates_uri: PyList[str] | None = Field(
        None, alias="instantiatesUri", serialization_alias="instantiatesUri"
    )
    medium: PyList[CodeableConcept] | None = Field(
        None, alias="medium", serialization_alias="medium"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    part_of: PyList[Reference] | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    payload: PyList[CommunicationPayload] | 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"
    )
    received: str | None = Field(None, alias="received", serialization_alias="received")
    recipient: PyList[Reference] | None = Field(
        None, alias="recipient", serialization_alias="recipient"
    )
    sender: Reference | None = Field(None, alias="sender", serialization_alias="sender")
    sent: str | None = Field(None, alias="sent", serialization_alias="sent")
    status: Literal[
        "preparation",
        "in-progress",
        "not-done",
        "on-hold",
        "stopped",
        "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"
    )
    topic: CodeableConcept | None = Field(
        None, alias="topic", serialization_alias="topic"
    )

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