from enum import Enum

from rgltr.governance import is_visible
from rgltr.types import ToolRules


class Tag(Enum):
    A = "a"
    B = "b"


class Boundary(Enum):
    EXTERNAL = "external"
    INTERNAL = "internal"


def test_blocked_by_hides():
    rules = ToolRules(blocked_by=frozenset([Tag.A]))
    assert is_visible(rules, set(), {}) is True
    assert is_visible(rules, {Tag.A}, {}) is False


def test_boundary_rules():
    rules = ToolRules(boundary=Boundary.EXTERNAL)
    boundaries = {Boundary.EXTERNAL: True}
    assert is_visible(rules, set(), boundaries) is True
    assert is_visible(rules, {Tag.A}, boundaries) is False

    boundaries = {Boundary.EXTERNAL: [Tag.B]}
    assert is_visible(rules, {Tag.A}, boundaries) is True
    assert is_visible(rules, {Tag.B}, boundaries) is False


def test_boundary_blocks_when_tags_active():
    rules = ToolRules(boundary=Boundary.EXTERNAL, blocked_by=frozenset([Tag.A]))
    assert is_visible(rules, {Tag.A}, {Boundary.EXTERNAL: True}) is False
