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


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

    end: int | None = Field(None, alias="end", serialization_alias="end")
    f_score: float | None = Field(None, alias="fScore", serialization_alias="fScore")
    gt_fp: float | None = Field(None, alias="gtFP", serialization_alias="gtFP")
    method: CodeableConcept | None = Field(
        None, alias="method", serialization_alias="method"
    )
    precision: float | None = Field(
        None, alias="precision", serialization_alias="precision"
    )
    query_fp: float | None = Field(None, alias="queryFP", serialization_alias="queryFP")
    query_tp: float | None = Field(None, alias="queryTP", serialization_alias="queryTP")
    recall: float | None = Field(None, alias="recall", serialization_alias="recall")
    roc: MolecularSequenceQualityRoc | None = Field(
        None, alias="roc", serialization_alias="roc"
    )
    score: Quantity | None = Field(None, alias="score", serialization_alias="score")
    standard_sequence: CodeableConcept | None = Field(
        None, alias="standardSequence", serialization_alias="standardSequence"
    )
    start: int | None = Field(None, alias="start", serialization_alias="start")
    truth_fn: float | None = Field(None, alias="truthFN", serialization_alias="truthFN")
    truth_tp: float | None = Field(None, alias="truthTP", serialization_alias="truthTP")
    type: Literal["indel", "snp", "unknown"] = Field(
        alias="type", serialization_alias="type"
    )


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

    f_measure: PyList[float] | None = Field(
        None, alias="fMeasure", serialization_alias="fMeasure"
    )
    num_fn: PyList[int] | None = Field(None, alias="numFN", serialization_alias="numFN")
    num_fp: PyList[int] | None = Field(None, alias="numFP", serialization_alias="numFP")
    num_tp: PyList[int] | None = Field(None, alias="numTP", serialization_alias="numTP")
    precision: PyList[float] | None = Field(
        None, alias="precision", serialization_alias="precision"
    )
    score: PyList[int] | None = Field(None, alias="score", serialization_alias="score")
    sensitivity: PyList[float] | None = Field(
        None, alias="sensitivity", serialization_alias="sensitivity"
    )


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

    chromosome: CodeableConcept | None = Field(
        None, alias="chromosome", serialization_alias="chromosome"
    )
    genome_build: str | None = Field(
        None, alias="genomeBuild", serialization_alias="genomeBuild"
    )
    orientation: Literal["sense", "antisense"] | None = Field(
        None, alias="orientation", serialization_alias="orientation"
    )
    reference_seq_id: CodeableConcept | None = Field(
        None, alias="referenceSeqId", serialization_alias="referenceSeqId"
    )
    reference_seq_pointer: Reference | None = Field(
        None, alias="referenceSeqPointer", serialization_alias="referenceSeqPointer"
    )
    reference_seq_string: str | None = Field(
        None, alias="referenceSeqString", serialization_alias="referenceSeqString"
    )
    strand: Literal["watson", "crick"] | None = Field(
        None, alias="strand", serialization_alias="strand"
    )
    window_end: int | None = Field(
        None, alias="windowEnd", serialization_alias="windowEnd"
    )
    window_start: int | None = Field(
        None, alias="windowStart", serialization_alias="windowStart"
    )


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

    dataset_id: str | None = Field(
        None, alias="datasetId", serialization_alias="datasetId"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    readset_id: str | None = Field(
        None, alias="readsetId", serialization_alias="readsetId"
    )
    type: Literal["directlink", "openapi", "login", "oauth", "other"] = Field(
        alias="type", serialization_alias="type"
    )
    url: str | None = Field(None, alias="url", serialization_alias="url")
    variantset_id: str | None = Field(
        None, alias="variantsetId", serialization_alias="variantsetId"
    )


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

    exact: bool | None = Field(None, alias="exact", serialization_alias="exact")
    inner: MolecularSequenceStructureVariantInner | None = Field(
        None, alias="inner", serialization_alias="inner"
    )
    length: int | None = Field(None, alias="length", serialization_alias="length")
    outer: MolecularSequenceStructureVariantOuter | None = Field(
        None, alias="outer", serialization_alias="outer"
    )
    variant_type: CodeableConcept | None = Field(
        None, alias="variantType", serialization_alias="variantType"
    )


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

    end: int | None = Field(None, alias="end", serialization_alias="end")
    start: int | None = Field(None, alias="start", serialization_alias="start")


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

    end: int | None = Field(None, alias="end", serialization_alias="end")
    start: int | None = Field(None, alias="start", serialization_alias="start")


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

    cigar: str | None = Field(None, alias="cigar", serialization_alias="cigar")
    end: int | None = Field(None, alias="end", serialization_alias="end")
    observed_allele: str | None = Field(
        None, alias="observedAllele", serialization_alias="observedAllele"
    )
    reference_allele: str | None = Field(
        None, alias="referenceAllele", serialization_alias="referenceAllele"
    )
    start: int | None = Field(None, alias="start", serialization_alias="start")
    variant_pointer: Reference | None = Field(
        None, alias="variantPointer", serialization_alias="variantPointer"
    )


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

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

    coordinate_system: int = Field(
        alias="coordinateSystem", serialization_alias="coordinateSystem"
    )
    device: Reference | None = Field(None, alias="device", serialization_alias="device")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    observed_seq: str | None = Field(
        None, alias="observedSeq", serialization_alias="observedSeq"
    )
    patient: Reference | None = Field(
        None, alias="patient", serialization_alias="patient"
    )
    performer: Reference | None = Field(
        None, alias="performer", serialization_alias="performer"
    )
    pointer: PyList[Reference] | None = Field(
        None, alias="pointer", serialization_alias="pointer"
    )
    quality: PyList[MolecularSequenceQuality] | None = Field(
        None, alias="quality", serialization_alias="quality"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    read_coverage: int | None = Field(
        None, alias="readCoverage", serialization_alias="readCoverage"
    )
    reference_seq: MolecularSequenceReferenceSeq | None = Field(
        None, alias="referenceSeq", serialization_alias="referenceSeq"
    )
    repository: PyList[MolecularSequenceRepository] | None = Field(
        None, alias="repository", serialization_alias="repository"
    )
    specimen: Reference | None = Field(
        None, alias="specimen", serialization_alias="specimen"
    )
    structure_variant: PyList[MolecularSequenceStructureVariant] | None = Field(
        None, alias="structureVariant", serialization_alias="structureVariant"
    )
    type: Literal["aa", "dna", "rna"] | None = Field(
        None, alias="type", serialization_alias="type"
    )
    variant: PyList[MolecularSequenceVariant] | None = Field(
        None, alias="variant", serialization_alias="variant"
    )

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