"""
Character status generated by system.
"""

from typing import Any, List, Literal

from ....utils.class_registry import register_class
from .base import RoundCharacterStatus
from ...modifiable_values import DamageIncreaseValue
from ...consts import DamageElementalType, IconType
from ...event import MakeDamageEventArguments
from ...action import Actions


class Frozen_3_3(RoundCharacterStatus):
    """
    Frozen.
    """

    name: Literal["Frozen"] = "Frozen"
    version: Literal["3.3"] = "3.3"
    usage: int = 1
    max_usage: int = 1
    icon_type: Literal[IconType.FROZEN] = IconType.FROZEN

    def value_modifier_DAMAGE_INCREASE(
        self, value: DamageIncreaseValue, match: Any, mode: Literal["TEST", "REAL"]
    ) -> DamageIncreaseValue:
        """
        Increase damage for pyro and physical damages to self by 2, and
        decrease usage.
        """
        if not value.is_corresponding_character_receive_damage(self.position, match):
            # not this character receive damage, not modify
            return value
        if (
            value.damage_elemental_type
            in [
                DamageElementalType.PYRO,
                DamageElementalType.PHYSICAL,
            ]
            and self.usage > 0
        ):
            value.damage += 2
            assert mode == "REAL"
            self.usage -= 1
        return value

    def event_handler_MAKE_DAMAGE(
        self, event: MakeDamageEventArguments, match: Any
    ) -> List[Actions]:
        """
        When damage made, check whether the status should be removed.
        Not trigger on AFTER_MAKE_DAMAGE because when damage made, run out
        of usage, but new one is generated, should remove first then generate
        new one, otherwise newly updated status will be removed.
        """
        return list(self.check_should_remove())


register_class(Frozen_3_3)
