from typing import Self
from .Exceptions import AssociativityException


class Priority:
    def __init__(self, associative: int|None, primary: int, secondary: int = 0):
        self.primary = primary
        self.secondary = secondary
        self.associative = associative

    def __eq__(self, other: Self):
        return True if self.primary == other.primary and \
                       self.secondary == other.secondary and \
                       self.associative == other.associative \
                       else False

    def __gt__(self, other: Self):
        if not self.secondary == other.secondary:
            return True if self.secondary > other.secondary else False
        if not self.primary == other.primary:
            return True if self.primary > other.primary else False
        if not self.associative and other.associative:
            raise AssociativityException(f"Bad associativity comparison between objects {self} and {other}")
        if not self.associative == other.associative:
            return True if self.associative > other.associative else False
        return False
