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


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

    endpoint: str | None = Field(None, alias="endpoint", serialization_alias="endpoint")
    header: PyList[str] | None = Field(
        None, alias="header", serialization_alias="header"
    )
    payload: str | None = Field(None, alias="payload", serialization_alias="payload")
    type: Literal["rest-hook", "websocket", "email", "sms", "message"] = Field(
        alias="type", serialization_alias="type"
    )


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

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

    channel: SubscriptionChannel = Field(alias="channel", serialization_alias="channel")
    contact: PyList[ContactPoint] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    criteria: str = Field(alias="criteria", serialization_alias="criteria")
    end: str | None = Field(None, alias="end", serialization_alias="end")
    error: str | None = Field(None, alias="error", serialization_alias="error")
    reason: str = Field(alias="reason", serialization_alias="reason")
    status: Literal["requested", "active", "error", "off"] = Field(
        alias="status", serialization_alias="status"
    )

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