"""Tests for Cat-VRS models."""

from __future__ import annotations

from ai4gh.specs.cat_vrs.models import (
    CanonicalVariationConstraint,
    CategoricalVariation,
    DefiningContextType,
    ProteinSequenceConsequence,
)
from ai4gh.specs.vrs.models import CopyChange, SequenceLocation, SequenceReference


class TestDefiningContextType:
    def test_enum_values(self) -> None:
        assert DefiningContextType.GENOMIC == "genomic"
        assert DefiningContextType.TRANSCRIPT == "transcript"
        assert DefiningContextType.PROTEIN == "protein"


class TestCanonicalVariationConstraint:
    def test_defaults(self) -> None:
        cvc = CanonicalVariationConstraint()
        assert cvc.type == "CanonicalVariationConstraint"
        assert cvc.complement is False
        assert cvc.copies is None

    def test_with_location(self) -> None:
        loc = SequenceLocation(
            sequenceReference=SequenceReference(refgetAccession="SQ.abc123"),
        )
        cvc = CanonicalVariationConstraint(
            defining_context=loc,
            copies=2,
            copy_change=CopyChange.EFO_0030067,
        )
        assert cvc.defining_context is not None
        assert cvc.copies == 2

    def test_complement(self) -> None:
        cvc = CanonicalVariationConstraint(complement=True)
        assert cvc.complement is True

    def test_with_sequence_reference(self) -> None:
        ref = SequenceReference(refgetAccession="SQ.abc123")
        cvc = CanonicalVariationConstraint(defining_context=ref)
        assert cvc.defining_context is not None


class TestCategoricalVariation:
    def test_defaults(self) -> None:
        cv = CategoricalVariation()
        assert cv.type == "CategoricalVariation"
        assert cv.members is None

    def test_full(self) -> None:
        cv = CategoricalVariation(
            id="catvar:001",
            label="BRCA1 Loss-of-Function",
            description="Any loss-of-function variant in BRCA1",
            members=[
                CanonicalVariationConstraint(copies=0),
                CanonicalVariationConstraint(copies=1),
            ],
            defining_context_type=DefiningContextType.GENOMIC,
        )
        assert cv.id == "catvar:001"
        assert len(cv.members) == 2
        assert cv.defining_context_type is DefiningContextType.GENOMIC


class TestProteinSequenceConsequence:
    def test_defaults(self) -> None:
        psc = ProteinSequenceConsequence()
        assert psc.type == "ProteinSequenceConsequence"
        assert psc.defining_context is None

    def test_with_context(self) -> None:
        loc = SequenceLocation(
            sequenceReference=SequenceReference(refgetAccession="SQ.protein123"),
        )
        psc = ProteinSequenceConsequence(
            defining_context=loc,
            label="p.Val600Glu",
            description="BRAF V600E",
        )
        assert psc.label == "p.Val600Glu"
