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


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

    item: Reference = Field(alias="item", serialization_alias="item")
    relationtype: Literal["triggers", "is-replaced-by"] = Field(
        alias="relationtype", serialization_alias="relationtype"
    )


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

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

    additional_characteristic: PyList[CodeableConcept] | None = Field(
        None,
        alias="additionalCharacteristic",
        serialization_alias="additionalCharacteristic",
    )
    additional_classification: PyList[CodeableConcept] | None = Field(
        None,
        alias="additionalClassification",
        serialization_alias="additionalClassification",
    )
    additional_identifier: PyList[Identifier] | None = Field(
        None, alias="additionalIdentifier", serialization_alias="additionalIdentifier"
    )
    classification: PyList[CodeableConcept] | None = Field(
        None, alias="classification", serialization_alias="classification"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    last_updated: str | None = Field(
        None, alias="lastUpdated", serialization_alias="lastUpdated"
    )
    orderable: bool = Field(alias="orderable", serialization_alias="orderable")
    referenced_item: Reference = Field(
        alias="referencedItem", serialization_alias="referencedItem"
    )
    related_entry: PyList[CatalogEntryRelatedEntry] | None = Field(
        None, alias="relatedEntry", serialization_alias="relatedEntry"
    )
    status: Literal["draft", "active", "retired", "unknown"] | None = Field(
        None, alias="status", serialization_alias="status"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")
    validity_period: Period | None = Field(
        None, alias="validityPeriod", serialization_alias="validityPeriod"
    )
    valid_to: str | None = Field(None, alias="validTo", serialization_alias="validTo")

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