from decimal import Decimal

import pytest
from src.domain.entities.attention import Attention, AttentionSeverity, AttentionType, LastMonthUsageParameters


class TestAttention:
    class TestSerialization:
        def test(self):
            """Attentionのシリアライズが正しいことを確認する"""
            expected_severity = "low"
            expected_type = "last_month_usage"
            expected_parameters = {"last_month_usage": 10000}

            actual_attention = Attention(
                severity=AttentionSeverity.LOW,
                type=AttentionType.LAST_MONTH_USAGE,
                parameters=LastMonthUsageParameters(last_month_usage=Decimal(10000)),
            )
            serialized = actual_attention.model_dump()
            assert serialized["severity"] == expected_severity
            assert serialized["type"] == expected_type
            assert serialized["parameters"] == expected_parameters

    class TestParameters:
        def test_invalid_parameters_for_last_month_usage(self):
            """LAST_MONTH_USAGEタイプでparametersが不正"""
            with pytest.raises(
                ValueError,
                match="parameters must be LastMonthUsageParameters for LAST_MONTH_USAGE type",
            ):
                Attention(
                    severity=AttentionSeverity.LOW,
                    type=AttentionType.LAST_MONTH_USAGE,
                    parameters=None,
                )

        def test_invalid_parameters_for_exceeded(self):
            """EXCEEDEDタイプでparametersが不正"""
            with pytest.raises(ValueError, match="parameters must be None for EXCEEDED type"):
                Attention(
                    severity=AttentionSeverity.HIGH,
                    type=AttentionType.EXCEEDED,
                    parameters=LastMonthUsageParameters(last_month_usage=Decimal(10000)),
                )
