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


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

    endpoint: str = Field(alias="endpoint", serialization_alias="endpoint")
    name: str | None = Field(None, alias="name", serialization_alias="name")
    receiver: Reference | None = Field(
        None, alias="receiver", serialization_alias="receiver"
    )
    target: Reference | None = Field(None, alias="target", serialization_alias="target")


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

    code: Literal["ok", "transient-error", "fatal-error"] = Field(
        alias="code", serialization_alias="code"
    )
    details: Reference | None = Field(
        None, alias="details", serialization_alias="details"
    )
    identifier: str = Field(alias="identifier", serialization_alias="identifier")


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

    contact: ContactPoint | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    endpoint: str = Field(alias="endpoint", serialization_alias="endpoint")
    name: str | None = Field(None, alias="name", serialization_alias="name")
    software: str | None = Field(None, alias="software", serialization_alias="software")
    version: str | None = Field(None, alias="version", serialization_alias="version")


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

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

    author: Reference | None = Field(None, alias="author", serialization_alias="author")
    definition: str | None = Field(
        None, alias="definition", serialization_alias="definition"
    )
    destination: PyList[MessageHeaderDestination] | None = Field(
        None, alias="destination", serialization_alias="destination"
    )
    enterer: Reference | None = Field(
        None, alias="enterer", serialization_alias="enterer"
    )
    event_coding: Coding | None = Field(
        None, alias="eventCoding", serialization_alias="eventCoding"
    )
    event_uri: str | None = Field(
        None, alias="eventUri", serialization_alias="eventUri"
    )
    focus: PyList[Reference] | None = Field(
        None, alias="focus", serialization_alias="focus"
    )
    reason: CodeableConcept | None = Field(
        None, alias="reason", serialization_alias="reason"
    )
    response: MessageHeaderResponse | None = Field(
        None, alias="response", serialization_alias="response"
    )
    responsible: Reference | None = Field(
        None, alias="responsible", serialization_alias="responsible"
    )
    sender: Reference | None = Field(None, alias="sender", serialization_alias="sender")
    source: MessageHeaderSource = Field(alias="source", serialization_alias="source")

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