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


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

    ratio_type: CodeableConcept | None = Field(
        None, alias="ratioType", serialization_alias="ratioType"
    )
    starting_material: PyList[SubstancePolymerMonomerSetStartingMaterial] | None = (
        Field(None, alias="startingMaterial", serialization_alias="startingMaterial")
    )


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

    amount: SubstanceAmount | None = Field(
        None, alias="amount", serialization_alias="amount"
    )
    is_defining: bool | None = Field(
        None, alias="isDefining", serialization_alias="isDefining"
    )
    material: CodeableConcept | None = Field(
        None, alias="material", serialization_alias="material"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    average_molecular_formula: str | None = Field(
        None,
        alias="averageMolecularFormula",
        serialization_alias="averageMolecularFormula",
    )
    number_of_units: int | None = Field(
        None, alias="numberOfUnits", serialization_alias="numberOfUnits"
    )
    repeat_unit: PyList[SubstancePolymerRepeatRepeatUnit] | None = Field(
        None, alias="repeatUnit", serialization_alias="repeatUnit"
    )
    repeat_unit_amount_type: CodeableConcept | None = Field(
        None, alias="repeatUnitAmountType", serialization_alias="repeatUnitAmountType"
    )


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

    amount: SubstanceAmount | None = Field(
        None, alias="amount", serialization_alias="amount"
    )
    degree_of_polymerisation: (
        PyList[SubstancePolymerRepeatRepeatUnitDegreeOfPolymerisation] | None
    ) = Field(
        None,
        alias="degreeOfPolymerisation",
        serialization_alias="degreeOfPolymerisation",
    )
    orientation_of_polymerisation: CodeableConcept | None = Field(
        None,
        alias="orientationOfPolymerisation",
        serialization_alias="orientationOfPolymerisation",
    )
    repeat_unit: str | None = Field(
        None, alias="repeatUnit", serialization_alias="repeatUnit"
    )
    structural_representation: (
        PyList[SubstancePolymerRepeatRepeatUnitStructuralRepresentation] | None
    ) = Field(
        None,
        alias="structuralRepresentation",
        serialization_alias="structuralRepresentation",
    )


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

    amount: SubstanceAmount | None = Field(
        None, alias="amount", serialization_alias="amount"
    )
    degree: CodeableConcept | None = Field(
        None, alias="degree", serialization_alias="degree"
    )


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

    attachment: Attachment | None = Field(
        None, alias="attachment", serialization_alias="attachment"
    )
    representation: str | None = Field(
        None, alias="representation", serialization_alias="representation"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

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

    class_: CodeableConcept | None = Field(
        None, alias="class", serialization_alias="class"
    )
    copolymer_connectivity: PyList[CodeableConcept] | None = Field(
        None, alias="copolymerConnectivity", serialization_alias="copolymerConnectivity"
    )
    geometry: CodeableConcept | None = Field(
        None, alias="geometry", serialization_alias="geometry"
    )
    modification: PyList[str] | None = Field(
        None, alias="modification", serialization_alias="modification"
    )
    monomer_set: PyList[SubstancePolymerMonomerSet] | None = Field(
        None, alias="monomerSet", serialization_alias="monomerSet"
    )
    repeat: PyList[SubstancePolymerRepeat] | None = Field(
        None, alias="repeat", serialization_alias="repeat"
    )

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