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


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

    expression: str = Field(alias="expression", serialization_alias="expression")
    type: Literal["fhirpath", "element", "extension"] = Field(
        alias="type", serialization_alias="type"
    )


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

    element: PyList[ElementDefinition] = Field(
        alias="element", serialization_alias="element"
    )


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

    comment: str | None = Field(None, alias="comment", serialization_alias="comment")
    identity: str = Field(alias="identity", serialization_alias="identity")
    name: str | None = Field(None, alias="name", serialization_alias="name")
    uri: str | None = Field(None, alias="uri", serialization_alias="uri")


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

    element: PyList[ElementDefinition] = Field(
        alias="element", serialization_alias="element"
    )


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

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

    abstract: bool = Field(alias="abstract", serialization_alias="abstract")
    base_definition: str | None = Field(
        None, alias="baseDefinition", serialization_alias="baseDefinition"
    )
    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    context: PyList[StructureDefinitionContext] | None = Field(
        None, alias="context", serialization_alias="context"
    )
    context_invariant: PyList[str] | None = Field(
        None, alias="contextInvariant", serialization_alias="contextInvariant"
    )
    copyright: str | None = Field(
        None, alias="copyright", serialization_alias="copyright"
    )
    date: str | None = Field(None, alias="date", serialization_alias="date")
    derivation: Literal["specialization", "constraint"] | None = Field(
        None, alias="derivation", serialization_alias="derivation"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    differential: StructureDefinitionDifferential | None = Field(
        None, alias="differential", serialization_alias="differential"
    )
    experimental: bool | None = Field(
        None, alias="experimental", serialization_alias="experimental"
    )
    fhir_version: (
        Literal[
            "0.01",
            "0.05",
            "0.06",
            "0.11",
            "0.0.80",
            "0.0.81",
            "0.0.82",
            "0.4.0",
            "0.5.0",
            "1.0.0",
            "1.0.1",
            "1.0.2",
            "1.1.0",
            "1.4.0",
            "1.6.0",
            "1.8.0",
            "3.0.0",
            "3.0.1",
            "3.3.0",
            "3.5.0",
            "4.0.0",
            "4.0.1",
        ]
        | None
    ) = Field(None, alias="fhirVersion", serialization_alias="fhirVersion")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    keyword: PyList[Coding] | None = Field(
        None, alias="keyword", serialization_alias="keyword"
    )
    kind: Literal["primitive-type", "complex-type", "resource", "logical"] = Field(
        alias="kind", serialization_alias="kind"
    )
    mapping: PyList[StructureDefinitionMapping] | None = Field(
        None, alias="mapping", serialization_alias="mapping"
    )
    name: str = Field(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")
    snapshot: StructureDefinitionSnapshot | None = Field(
        None, alias="snapshot", serialization_alias="snapshot"
    )
    status: Literal["draft", "active", "retired", "unknown"] = Field(
        alias="status", serialization_alias="status"
    )
    title: str | None = Field(None, alias="title", serialization_alias="title")
    type: str = Field(alias="type", serialization_alias="type")
    url: str = Field(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) -> StructureDefinition:
        return cls.model_validate_json(json)
