"""Map P2HS billing to Discord community role names."""
from __future__ import annotations

from typing import Iterable, Optional

ROLE_EVALUATING = "Evaluating"
ROLE_CUSTOMER = "Customer"
ROLE_PRO_CUSTOMER = "Pro Customer"

MANAGED_ROLE_NAMES = (ROLE_EVALUATING, ROLE_CUSTOMER, ROLE_PRO_CUSTOMER)

_PRO_SLUGS = frozenset({"pro", "enterprise"})
_PAID_SLUGS = frozenset({"basic", "pro", "enterprise"})


def community_role_name(*, plan_slugs: Iterable[Optional[str]], any_paid: bool) -> str:
    slugs = {(slug or "").strip().lower() for slug in plan_slugs if slug}
    if slugs & _PRO_SLUGS:
        return ROLE_PRO_CUSTOMER
    if any_paid or (slugs & _PAID_SLUGS):
        return ROLE_CUSTOMER
    return ROLE_EVALUATING
