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


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

    date: str | None = Field(None, alias="date", serialization_alias="date")
    deleted: bool | None = Field(None, alias="deleted", serialization_alias="deleted")
    flag: CodeableConcept | None = Field(None, alias="flag", serialization_alias="flag")
    item: Reference = Field(alias="item", serialization_alias="item")


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

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

    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    date: str | None = Field(None, alias="date", serialization_alias="date")
    empty_reason: CodeableConcept | None = Field(
        None, alias="emptyReason", serialization_alias="emptyReason"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    entry: PyList[ListEntry] | None = Field(
        None, alias="entry", serialization_alias="entry"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    mode: Literal["working", "snapshot", "changes"] = Field(
        alias="mode", serialization_alias="mode"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    ordered_by: CodeableConcept | None = Field(
        None, alias="orderedBy", serialization_alias="orderedBy"
    )
    source: Reference | None = Field(None, alias="source", serialization_alias="source")
    status: Literal["current", "retired", "entered-in-error"] = Field(
        alias="status", serialization_alias="status"
    )
    subject: Reference | None = Field(
        None, alias="subject", serialization_alias="subject"
    )
    title: str | None = Field(None, alias="title", serialization_alias="title")

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