# 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, PositiveInt
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    Address,
    Age,
    Annotation,
    Attachment,
    BackboneElement,
    CodeableConcept,
    Coding,
    ContactDetail,
    ContactPoint,
    Contributor,
    Count,
    DataRequirement,
    Distance,
    Dosage,
    Duration,
    Expression,
    HumanName,
    Identifier,
    Meta,
    Money,
    ParameterDefinition,
    Period,
    Quantity,
    Range,
    Ratio,
    Reference,
    RelatedArtifact,
    SampledData,
    Signature,
    Timing,
    TriggerDefinition,
    UsageContext,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    documentation: str | None = Field(
        None, alias="documentation", serialization_alias="documentation"
    )
    extends: str | None = Field(None, alias="extends", serialization_alias="extends")
    input: PyList[StructureMapGroupInput] = Field(
        alias="input", serialization_alias="input"
    )
    name: str = Field(alias="name", serialization_alias="name")
    rule: PyList[StructureMapGroupRule] = Field(
        alias="rule", serialization_alias="rule"
    )
    type_mode: Literal["none", "types", "type-and-types"] = Field(
        alias="typeMode", serialization_alias="typeMode"
    )


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

    documentation: str | None = Field(
        None, alias="documentation", serialization_alias="documentation"
    )
    mode: Literal["source", "target"] = Field(alias="mode", serialization_alias="mode")
    name: str = Field(alias="name", serialization_alias="name")
    type: str | None = Field(None, alias="type", serialization_alias="type")


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

    dependent: PyList[StructureMapGroupRuleDependent] | None = Field(
        None, alias="dependent", serialization_alias="dependent"
    )
    documentation: str | None = Field(
        None, alias="documentation", serialization_alias="documentation"
    )
    name: str = Field(alias="name", serialization_alias="name")
    rule: PyList[StructureMapGroupRule] | None = Field(
        None, alias="rule", serialization_alias="rule"
    )
    source: PyList[StructureMapGroupRuleSource] = Field(
        alias="source", serialization_alias="source"
    )
    target: PyList[StructureMapGroupRuleTarget] | None = Field(
        None, alias="target", serialization_alias="target"
    )


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

    name: str = Field(alias="name", serialization_alias="name")
    variable: PyList[str] = Field(alias="variable", serialization_alias="variable")


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

    check: str | None = Field(None, alias="check", serialization_alias="check")
    condition: str | None = Field(
        None, alias="condition", serialization_alias="condition"
    )
    context: str = Field(alias="context", serialization_alias="context")
    default_value_address: Address | None = Field(
        None, alias="defaultValueAddress", serialization_alias="defaultValueAddress"
    )
    default_value_age: Age | None = Field(
        None, alias="defaultValueAge", serialization_alias="defaultValueAge"
    )
    default_value_annotation: Annotation | None = Field(
        None,
        alias="defaultValueAnnotation",
        serialization_alias="defaultValueAnnotation",
    )
    default_value_attachment: Attachment | None = Field(
        None,
        alias="defaultValueAttachment",
        serialization_alias="defaultValueAttachment",
    )
    default_value_base64binary: str | None = Field(
        None,
        alias="defaultValueBase64Binary",
        serialization_alias="defaultValueBase64Binary",
    )
    default_value_boolean: bool | None = Field(
        None, alias="defaultValueBoolean", serialization_alias="defaultValueBoolean"
    )
    default_value_canonical: str | None = Field(
        None, alias="defaultValueCanonical", serialization_alias="defaultValueCanonical"
    )
    default_value_code: str | None = Field(
        None, alias="defaultValueCode", serialization_alias="defaultValueCode"
    )
    default_value_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="defaultValueCodeableConcept",
        serialization_alias="defaultValueCodeableConcept",
    )
    default_value_coding: Coding | None = Field(
        None, alias="defaultValueCoding", serialization_alias="defaultValueCoding"
    )
    default_value_contact_detail: ContactDetail | None = Field(
        None,
        alias="defaultValueContactDetail",
        serialization_alias="defaultValueContactDetail",
    )
    default_value_contact_point: ContactPoint | None = Field(
        None,
        alias="defaultValueContactPoint",
        serialization_alias="defaultValueContactPoint",
    )
    default_value_contributor: Contributor | None = Field(
        None,
        alias="defaultValueContributor",
        serialization_alias="defaultValueContributor",
    )
    default_value_count: Count | None = Field(
        None, alias="defaultValueCount", serialization_alias="defaultValueCount"
    )
    default_value_data_requirement: DataRequirement | None = Field(
        None,
        alias="defaultValueDataRequirement",
        serialization_alias="defaultValueDataRequirement",
    )
    default_value_date: str | None = Field(
        None, alias="defaultValueDate", serialization_alias="defaultValueDate"
    )
    default_value_date_time: str | None = Field(
        None, alias="defaultValueDateTime", serialization_alias="defaultValueDateTime"
    )
    default_value_decimal: float | None = Field(
        None, alias="defaultValueDecimal", serialization_alias="defaultValueDecimal"
    )
    default_value_distance: Distance | None = Field(
        None, alias="defaultValueDistance", serialization_alias="defaultValueDistance"
    )
    default_value_dosage: Dosage | None = Field(
        None, alias="defaultValueDosage", serialization_alias="defaultValueDosage"
    )
    default_value_duration: Duration | None = Field(
        None, alias="defaultValueDuration", serialization_alias="defaultValueDuration"
    )
    default_value_expression: Expression | None = Field(
        None,
        alias="defaultValueExpression",
        serialization_alias="defaultValueExpression",
    )
    default_value_human_name: HumanName | None = Field(
        None, alias="defaultValueHumanName", serialization_alias="defaultValueHumanName"
    )
    default_value_id: str | None = Field(
        None, alias="defaultValueId", serialization_alias="defaultValueId"
    )
    default_value_identifier: Identifier | None = Field(
        None,
        alias="defaultValueIdentifier",
        serialization_alias="defaultValueIdentifier",
    )
    default_value_instant: str | None = Field(
        None, alias="defaultValueInstant", serialization_alias="defaultValueInstant"
    )
    default_value_integer: int | None = Field(
        None, alias="defaultValueInteger", serialization_alias="defaultValueInteger"
    )
    default_value_markdown: str | None = Field(
        None, alias="defaultValueMarkdown", serialization_alias="defaultValueMarkdown"
    )
    default_value_meta: Meta | None = Field(
        None, alias="defaultValueMeta", serialization_alias="defaultValueMeta"
    )
    default_value_money: Money | None = Field(
        None, alias="defaultValueMoney", serialization_alias="defaultValueMoney"
    )
    default_value_oid: str | None = Field(
        None, alias="defaultValueOid", serialization_alias="defaultValueOid"
    )
    default_value_parameter_definition: ParameterDefinition | None = Field(
        None,
        alias="defaultValueParameterDefinition",
        serialization_alias="defaultValueParameterDefinition",
    )
    default_value_period: Period | None = Field(
        None, alias="defaultValuePeriod", serialization_alias="defaultValuePeriod"
    )
    default_value_positive_int: PositiveInt | None = Field(
        None,
        alias="defaultValuePositiveInt",
        serialization_alias="defaultValuePositiveInt",
    )
    default_value_quantity: Quantity | None = Field(
        None, alias="defaultValueQuantity", serialization_alias="defaultValueQuantity"
    )
    default_value_range: Range | None = Field(
        None, alias="defaultValueRange", serialization_alias="defaultValueRange"
    )
    default_value_ratio: Ratio | None = Field(
        None, alias="defaultValueRatio", serialization_alias="defaultValueRatio"
    )
    default_value_reference: Reference | None = Field(
        None, alias="defaultValueReference", serialization_alias="defaultValueReference"
    )
    default_value_related_artifact: RelatedArtifact | None = Field(
        None,
        alias="defaultValueRelatedArtifact",
        serialization_alias="defaultValueRelatedArtifact",
    )
    default_value_sampled_data: SampledData | None = Field(
        None,
        alias="defaultValueSampledData",
        serialization_alias="defaultValueSampledData",
    )
    default_value_signature: Signature | None = Field(
        None, alias="defaultValueSignature", serialization_alias="defaultValueSignature"
    )
    default_value_string: str | None = Field(
        None, alias="defaultValueString", serialization_alias="defaultValueString"
    )
    default_value_time: str | None = Field(
        None, alias="defaultValueTime", serialization_alias="defaultValueTime"
    )
    default_value_timing: Timing | None = Field(
        None, alias="defaultValueTiming", serialization_alias="defaultValueTiming"
    )
    default_value_trigger_definition: TriggerDefinition | None = Field(
        None,
        alias="defaultValueTriggerDefinition",
        serialization_alias="defaultValueTriggerDefinition",
    )
    default_value_unsigned_int: int | None = Field(
        None,
        alias="defaultValueUnsignedInt",
        serialization_alias="defaultValueUnsignedInt",
    )
    default_value_uri: str | None = Field(
        None, alias="defaultValueUri", serialization_alias="defaultValueUri"
    )
    default_value_url: str | None = Field(
        None, alias="defaultValueUrl", serialization_alias="defaultValueUrl"
    )
    default_value_usage_context: UsageContext | None = Field(
        None,
        alias="defaultValueUsageContext",
        serialization_alias="defaultValueUsageContext",
    )
    default_value_uuid: str | None = Field(
        None, alias="defaultValueUuid", serialization_alias="defaultValueUuid"
    )
    element: str | None = Field(None, alias="element", serialization_alias="element")
    list_mode: Literal["first", "not_first", "last", "not_last", "only_one"] | None = (
        Field(None, alias="listMode", serialization_alias="listMode")
    )
    log_message: str | None = Field(
        None, alias="logMessage", serialization_alias="logMessage"
    )
    max: str | None = Field(None, alias="max", serialization_alias="max")
    min: int | None = Field(None, alias="min", serialization_alias="min")
    type: str | None = Field(None, alias="type", serialization_alias="type")
    variable: str | None = Field(None, alias="variable", serialization_alias="variable")


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

    context: str | None = Field(None, alias="context", serialization_alias="context")
    context_type: Literal["type", "variable"] | None = Field(
        None, alias="contextType", serialization_alias="contextType"
    )
    element: str | None = Field(None, alias="element", serialization_alias="element")
    list_mode: PyList[Literal["first", "share", "last", "collate"]] | None = Field(
        None, alias="listMode", serialization_alias="listMode"
    )
    list_rule_id: str | None = Field(
        None, alias="listRuleId", serialization_alias="listRuleId"
    )
    parameter: PyList[StructureMapGroupRuleTargetParameter] | None = Field(
        None, alias="parameter", serialization_alias="parameter"
    )
    transform: (
        Literal[
            "create",
            "copy",
            "truncate",
            "escape",
            "cast",
            "append",
            "translate",
            "reference",
            "dateOp",
            "uuid",
            "pointer",
            "evaluate",
            "cc",
            "c",
            "qty",
            "id",
            "cp",
        ]
        | None
    ) = Field(None, alias="transform", serialization_alias="transform")
    variable: str | None = Field(None, alias="variable", serialization_alias="variable")


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

    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_decimal: float | None = Field(
        None, alias="valueDecimal", serialization_alias="valueDecimal"
    )
    value_id: str | None = Field(None, alias="valueId", serialization_alias="valueId")
    value_integer: int | None = Field(
        None, alias="valueInteger", serialization_alias="valueInteger"
    )
    value_string: str | None = Field(
        None, alias="valueString", serialization_alias="valueString"
    )


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

    alias: str | None = Field(None, alias="alias", serialization_alias="alias")
    documentation: str | None = Field(
        None, alias="documentation", serialization_alias="documentation"
    )
    mode: Literal["source", "queried", "target", "produced"] = Field(
        alias="mode", serialization_alias="mode"
    )
    url: str = Field(alias="url", serialization_alias="url")


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

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

    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"
    )
    experimental: bool | None = Field(
        None, alias="experimental", serialization_alias="experimental"
    )
    group: PyList[StructureMapGroup] = Field(alias="group", serialization_alias="group")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    import_: PyList[str] | None = Field(
        None, alias="import", serialization_alias="import"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    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")
    status: Literal["draft", "active", "retired", "unknown"] = Field(
        alias="status", serialization_alias="status"
    )
    structure: PyList[StructureMapStructure] | None = Field(
        None, alias="structure", serialization_alias="structure"
    )
    title: str | None = Field(None, alias="title", serialization_alias="title")
    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) -> StructureMap:
        return cls.model_validate_json(json)
