# 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

from fhirschemapy.R4B.base import (
    BackboneElement,
    CodeableConcept,
    Identifier,
    Quantity,
    Range,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    classification: CodeableConcept | None = Field(
        None, alias="classification", serialization_alias="classification"
    )
    domain: CodeableConcept | None = Field(
        None, alias="domain", serialization_alias="domain"
    )
    source: PyList[Reference] | None = Field(
        None, alias="source", serialization_alias="source"
    )
    subtype: PyList[CodeableConcept] | None = Field(
        None, alias="subtype", serialization_alias="subtype"
    )


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

    gene: CodeableConcept | None = Field(None, alias="gene", serialization_alias="gene")
    gene_sequence_origin: CodeableConcept | None = Field(
        None, alias="geneSequenceOrigin", serialization_alias="geneSequenceOrigin"
    )
    source: PyList[Reference] | None = Field(
        None, alias="source", serialization_alias="source"
    )


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

    element: Identifier | None = Field(
        None, alias="element", serialization_alias="element"
    )
    source: PyList[Reference] | None = Field(
        None, alias="source", serialization_alias="source"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    amount_quantity: Quantity | None = Field(
        None, alias="amountQuantity", serialization_alias="amountQuantity"
    )
    amount_range: Range | None = Field(
        None, alias="amountRange", serialization_alias="amountRange"
    )
    amount_string: str | None = Field(
        None, alias="amountString", serialization_alias="amountString"
    )
    amount_type: CodeableConcept | None = Field(
        None, alias="amountType", serialization_alias="amountType"
    )
    interaction: CodeableConcept | None = Field(
        None, alias="interaction", serialization_alias="interaction"
    )
    organism: CodeableConcept | None = Field(
        None, alias="organism", serialization_alias="organism"
    )
    organism_type: CodeableConcept | None = Field(
        None, alias="organismType", serialization_alias="organismType"
    )
    source: PyList[Reference] | None = Field(
        None, alias="source", serialization_alias="source"
    )
    target: Identifier | None = Field(
        None, alias="target", serialization_alias="target"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

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

    classification: PyList[SubstanceReferenceInformationClassification] | None = Field(
        None, alias="classification", serialization_alias="classification"
    )
    comment: str | None = Field(None, alias="comment", serialization_alias="comment")
    gene: PyList[SubstanceReferenceInformationGene] | None = Field(
        None, alias="gene", serialization_alias="gene"
    )
    gene_element: PyList[SubstanceReferenceInformationGeneElement] | None = Field(
        None, alias="geneElement", serialization_alias="geneElement"
    )
    target: PyList[SubstanceReferenceInformationTarget] | None = Field(
        None, alias="target", serialization_alias="target"
    )

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