# 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, PositiveInt
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    BackboneElement,
    CodeableConcept,
    Identifier,
    Period,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    actor: Reference | None = Field(None, alias="actor", serialization_alias="actor")
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    required: Literal["required", "optional", "information-only"] | None = Field(
        None, alias="required", serialization_alias="required"
    )
    status: Literal["accepted", "declined", "tentative", "needs-action"] = Field(
        alias="status", serialization_alias="status"
    )
    type: PyList[CodeableConcept] | None = Field(
        None, alias="type", serialization_alias="type"
    )


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

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

    appointment_type: CodeableConcept | None = Field(
        None, alias="appointmentType", serialization_alias="appointmentType"
    )
    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    cancelation_reason: CodeableConcept | None = Field(
        None, alias="cancelationReason", serialization_alias="cancelationReason"
    )
    comment: str | None = Field(None, alias="comment", serialization_alias="comment")
    created: str | None = Field(None, alias="created", serialization_alias="created")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    end: str | None = Field(None, alias="end", serialization_alias="end")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    minutes_duration: PositiveInt | None = Field(
        None, alias="minutesDuration", serialization_alias="minutesDuration"
    )
    participant: PyList[AppointmentParticipant] = Field(
        alias="participant", serialization_alias="participant"
    )
    patient_instruction: str | None = Field(
        None, alias="patientInstruction", serialization_alias="patientInstruction"
    )
    priority: int | 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"
    )
    requested_period: PyList[Period] | None = Field(
        None, alias="requestedPeriod", serialization_alias="requestedPeriod"
    )
    service_category: PyList[CodeableConcept] | None = Field(
        None, alias="serviceCategory", serialization_alias="serviceCategory"
    )
    service_type: PyList[CodeableConcept] | None = Field(
        None, alias="serviceType", serialization_alias="serviceType"
    )
    slot: PyList[Reference] | None = Field(
        None, alias="slot", serialization_alias="slot"
    )
    specialty: PyList[CodeableConcept] | None = Field(
        None, alias="specialty", serialization_alias="specialty"
    )
    start: str | None = Field(None, alias="start", serialization_alias="start")
    status: Literal[
        "proposed",
        "pending",
        "booked",
        "arrived",
        "fulfilled",
        "cancelled",
        "noshow",
        "entered-in-error",
        "checked-in",
        "waitlist",
    ] = Field(alias="status", serialization_alias="status")
    supporting_information: PyList[Reference] | None = Field(
        None, alias="supportingInformation", serialization_alias="supportingInformation"
    )

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