# 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 ValueSetCompose(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    exclude: PyList[ValueSetComposeInclude] | None = Field(
        None, alias="exclude", serialization_alias="exclude"
    )
    inactive: bool | None = Field(
        None, alias="inactive", serialization_alias="inactive"
    )
    include: PyList[ValueSetComposeInclude] = Field(
        alias="include", serialization_alias="include"
    )
    locked_date: str | None = Field(
        None, alias="lockedDate", serialization_alias="lockedDate"
    )


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

    concept: PyList[ValueSetComposeIncludeConcept] | None = Field(
        None, alias="concept", serialization_alias="concept"
    )
    filter: PyList[ValueSetComposeIncludeFilter] | None = Field(
        None, alias="filter", serialization_alias="filter"
    )
    system: str | None = Field(None, alias="system", serialization_alias="system")
    value_set: PyList[str] | None = Field(
        None, alias="valueSet", serialization_alias="valueSet"
    )
    version: str | None = Field(None, alias="version", serialization_alias="version")


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

    code: str = Field(alias="code", serialization_alias="code")
    designation: PyList[ValueSetComposeIncludeConceptDesignation] | None = Field(
        None, alias="designation", serialization_alias="designation"
    )
    display: str | None = Field(None, alias="display", serialization_alias="display")


class ValueSetComposeIncludeConceptDesignation(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 ValueSetComposeIncludeFilter(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    op: Literal[
        "=",
        "is-a",
        "descendent-of",
        "is-not-a",
        "regex",
        "in",
        "not-in",
        "generalizes",
        "exists",
    ] = Field(alias="op", serialization_alias="op")
    property: str = Field(alias="property", serialization_alias="property")
    value: str = Field(alias="value", serialization_alias="value")


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

    contains: PyList[ValueSetExpansionContains] | None = Field(
        None, alias="contains", serialization_alias="contains"
    )
    identifier: str | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    offset: int | None = Field(None, alias="offset", serialization_alias="offset")
    parameter: PyList[ValueSetExpansionParameter] | None = Field(
        None, alias="parameter", serialization_alias="parameter"
    )
    timestamp: str = Field(alias="timestamp", serialization_alias="timestamp")
    total: int | None = Field(None, alias="total", serialization_alias="total")


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

    abstract: bool | None = Field(
        None, alias="abstract", serialization_alias="abstract"
    )
    code: str | None = Field(None, alias="code", serialization_alias="code")
    contains: PyList[ValueSetExpansionContains] | None = Field(
        None, alias="contains", serialization_alias="contains"
    )
    designation: PyList[ValueSetComposeIncludeConceptDesignation] | None = Field(
        None, alias="designation", serialization_alias="designation"
    )
    display: str | None = Field(None, alias="display", serialization_alias="display")
    inactive: bool | None = Field(
        None, alias="inactive", serialization_alias="inactive"
    )
    system: str | None = Field(None, alias="system", serialization_alias="system")
    version: str | None = Field(None, alias="version", serialization_alias="version")


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

    name: str = Field(alias="name", serialization_alias="name")
    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_code: str | None = Field(
        None, alias="valueCode", serialization_alias="valueCode"
    )
    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"
    )
    value_uri: str | None = Field(
        None, alias="valueUri", serialization_alias="valueUri"
    )


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

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

    compose: ValueSetCompose | None = Field(
        None, alias="compose", serialization_alias="compose"
    )
    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    copyright: str | None = Field(
        None, alias="copyright", serialization_alias="copyright"
    )
    date: str | None = Field(None, alias="date", serialization_alias="date")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    expansion: ValueSetExpansion | None = Field(
        None, alias="expansion", serialization_alias="expansion"
    )
    experimental: bool | None = Field(
        None, alias="experimental", serialization_alias="experimental"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    immutable: bool | None = Field(
        None, alias="immutable", serialization_alias="immutable"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    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"
    )
    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"
    )
    version: str | None = Field(None, alias="version", serialization_alias="version")

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