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


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

    comment: str | None = Field(None, alias="comment", serialization_alias="comment")
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    preferred: bool | None = Field(
        None, alias="preferred", serialization_alias="preferred"
    )
    type: Literal["oid", "uuid", "uri", "other"] = Field(
        alias="type", serialization_alias="type"
    )
    value: str = Field(alias="value", serialization_alias="value")


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

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

    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    date: str = Field(alias="date", serialization_alias="date")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    kind: Literal["codesystem", "identifier", "root"] = Field(
        alias="kind", serialization_alias="kind"
    )
    name: str = Field(alias="name", serialization_alias="name")
    publisher: str | None = Field(
        None, alias="publisher", serialization_alias="publisher"
    )
    responsible: str | None = Field(
        None, alias="responsible", serialization_alias="responsible"
    )
    status: Literal["draft", "active", "retired", "unknown"] = Field(
        alias="status", serialization_alias="status"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")
    unique_id: PyList[NamingSystemUniqueId] = Field(
        alias="uniqueId", serialization_alias="uniqueId"
    )
    usage: str | None = Field(None, alias="usage", serialization_alias="usage")
    use_context: PyList[UsageContext] | None = Field(
        None, alias="useContext", serialization_alias="useContext"
    )

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