from collections.abc import Collection, Sequence

from mahjong.constants import DRAGONS
from mahjong.hand_calculating.yaku import Yaku
from mahjong.utils import is_pon_or_kan


class Daisangen(Yaku):
    """大三元: The hand contains three sets of dragons."""

    yaku_id = 103
    name = "Daisangen"
    han_open = 13
    han_closed = 13
    is_yakuman = True

    def is_condition_met(self, hand: Collection[Sequence[int]], *args) -> bool:
        """Check whether the hand contains pon or kan sets of all three dragons."""
        count_of_dragon_pon_sets = 0
        for item in hand:
            if item[0] not in DRAGONS:
                continue
            if is_pon_or_kan(item):
                count_of_dragon_pon_sets += 1
        return count_of_dragon_pon_sets == 3
