from enum import Enum

from rgltr.decorators import boundary, policy, rules_for_tool, tag
from rgltr.types import PolicyDecision, PolicyRequest


class Tag(Enum):
    CUSTOMERS = "customers"


class Boundary(Enum):
    EXTERNAL = "external"


async def allow_policy(_: PolicyRequest) -> PolicyDecision:
    return PolicyDecision.allow("ok")


@tag(activates=[Tag.CUSTOMERS])
@boundary(Boundary.EXTERNAL)
@policy(require=[allow_policy], denied_message="nope")
async def sample() -> str:
    return "ok"


def test_rules_for_tool():
    rules = rules_for_tool(sample)
    assert Tag.CUSTOMERS in rules.activates
    assert rules.boundary == Boundary.EXTERNAL
    assert rules.policies.require
    assert rules.policies.denied_message == "nope"
