# 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 (
    Attachment,
    BackboneElement,
    CodeableConcept,
    Identifier,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    five_prime: CodeableConcept | None = Field(
        None, alias="fivePrime", serialization_alias="fivePrime"
    )
    length: int | None = Field(None, alias="length", serialization_alias="length")
    linkage: PyList[SubstanceNucleicAcidSubunitLinkage] | None = Field(
        None, alias="linkage", serialization_alias="linkage"
    )
    sequence: str | None = Field(None, alias="sequence", serialization_alias="sequence")
    sequence_attachment: Attachment | None = Field(
        None, alias="sequenceAttachment", serialization_alias="sequenceAttachment"
    )
    subunit: int | None = Field(None, alias="subunit", serialization_alias="subunit")
    sugar: PyList[SubstanceNucleicAcidSubunitSugar] | None = Field(
        None, alias="sugar", serialization_alias="sugar"
    )
    three_prime: CodeableConcept | None = Field(
        None, alias="threePrime", serialization_alias="threePrime"
    )


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

    connectivity: str | None = Field(
        None, alias="connectivity", serialization_alias="connectivity"
    )
    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    residue_site: str | None = Field(
        None, alias="residueSite", serialization_alias="residueSite"
    )


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

    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    residue_site: str | None = Field(
        None, alias="residueSite", serialization_alias="residueSite"
    )


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

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

    area_of_hybridisation: str | None = Field(
        None, alias="areaOfHybridisation", serialization_alias="areaOfHybridisation"
    )
    number_of_subunits: int | None = Field(
        None, alias="numberOfSubunits", serialization_alias="numberOfSubunits"
    )
    oligo_nucleotide_type: CodeableConcept | None = Field(
        None, alias="oligoNucleotideType", serialization_alias="oligoNucleotideType"
    )
    sequence_type: CodeableConcept | None = Field(
        None, alias="sequenceType", serialization_alias="sequenceType"
    )
    subunit: PyList[SubstanceNucleicAcidSubunit] | None = Field(
        None, alias="subunit", serialization_alias="subunit"
    )

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