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


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

    code: str = Field(alias="code", serialization_alias="code")
    concept: PyList[CodeSystemConcept] | None = Field(
        None, alias="concept", serialization_alias="concept"
    )
    definition: str | None = Field(
        None, alias="definition", serialization_alias="definition"
    )
    designation: PyList[CodeSystemConceptDesignation] | None = Field(
        None, alias="designation", serialization_alias="designation"
    )
    display: str | None = Field(None, alias="display", serialization_alias="display")
    property: PyList[CodeSystemConceptProperty] | None = Field(
        None, alias="property", serialization_alias="property"
    )


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

    language: str | None = Field(None, alias="language", serialization_alias="language")
    use: Coding | None = Field(None, alias="use", serialization_alias="use")
    value: str = Field(alias="value", serialization_alias="value")


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

    code: str = Field(alias="code", serialization_alias="code")
    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_code: str | None = Field(
        None, alias="valueCode", serialization_alias="valueCode"
    )
    value_coding: Coding | None = Field(
        None, alias="valueCoding", serialization_alias="valueCoding"
    )
    value_date_time: str | None = Field(
        None, alias="valueDateTime", serialization_alias="valueDateTime"
    )
    value_decimal: float | None = Field(
        None, alias="valueDecimal", serialization_alias="valueDecimal"
    )
    value_integer: int | None = Field(
        None, alias="valueInteger", serialization_alias="valueInteger"
    )
    value_string: str | None = Field(
        None, alias="valueString", serialization_alias="valueString"
    )


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

    code: str = Field(alias="code", serialization_alias="code")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    operator: PyList[
        Literal[
            "=",
            "is-a",
            "descendent-of",
            "is-not-a",
            "regex",
            "in",
            "not-in",
            "generalizes",
            "exists",
        ]
    ] = Field(alias="operator", serialization_alias="operator")
    value: str = Field(alias="value", serialization_alias="value")


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

    code: str = Field(alias="code", serialization_alias="code")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    type: Literal[
        "code", "Coding", "string", "integer", "boolean", "dateTime", "decimal"
    ] = Field(alias="type", serialization_alias="type")
    uri: str | None = Field(None, alias="uri", serialization_alias="uri")


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

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

    case_sensitive: bool | None = Field(
        None, alias="caseSensitive", serialization_alias="caseSensitive"
    )
    compositional: bool | None = Field(
        None, alias="compositional", serialization_alias="compositional"
    )
    concept: PyList[CodeSystemConcept] | None = Field(
        None, alias="concept", serialization_alias="concept"
    )
    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    content: Literal["not-present", "example", "fragment", "complete", "supplement"] = (
        Field(alias="content", serialization_alias="content")
    )
    copyright: str | None = Field(
        None, alias="copyright", serialization_alias="copyright"
    )
    count: int | None = Field(None, alias="count", serialization_alias="count")
    date: str | None = Field(None, alias="date", serialization_alias="date")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    experimental: bool | None = Field(
        None, alias="experimental", serialization_alias="experimental"
    )
    filter: PyList[CodeSystemFilter] | None = Field(
        None, alias="filter", serialization_alias="filter"
    )
    hierarchy_meaning: (
        Literal["grouped-by", "is-a", "part-of", "classified-with"] | None
    ) = Field(None, alias="hierarchyMeaning", serialization_alias="hierarchyMeaning")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    property: PyList[CodeSystemProperty] | None = Field(
        None, alias="property", serialization_alias="property"
    )
    publisher: str | None = Field(
        None, alias="publisher", serialization_alias="publisher"
    )
    purpose: str | None = Field(None, alias="purpose", serialization_alias="purpose")
    status: Literal["draft", "active", "retired", "unknown"] = Field(
        alias="status", serialization_alias="status"
    )
    supplements: str | None = Field(
        None, alias="supplements", serialization_alias="supplements"
    )
    title: str | None = Field(None, alias="title", serialization_alias="title")
    url: str | None = Field(None, alias="url", serialization_alias="url")
    use_context: PyList[UsageContext] | None = Field(
        None, alias="useContext", serialization_alias="useContext"
    )
    value_set: str | None = Field(
        None, alias="valueSet", serialization_alias="valueSet"
    )
    version: str | None = Field(None, alias="version", serialization_alias="version")
    version_needed: bool | None = Field(
        None, alias="versionNeeded", serialization_alias="versionNeeded"
    )

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