# Role definitions for Xenia POS
#
# Roles serve two purposes:
#   1. Label what a staff member actually does in the venue
#   2. Set default permission values when a member is created or permissions are reset
#
# After creation, permissions are per-member and can be overridden freely.
# SUPERADMIN is always fully privileged — the backend enforces this regardless of
# stored boolean values.

ALL_ROLES: list[dict] = [
    {"value": "superadmin",       "label": "Superadmin",         "label_el": "Superadmin"},
    {"value": "owner",            "label": "Owner",              "label_el": "Ιδιοκτήτης"},
    {"value": "store_manager",    "label": "Store Manager",      "label_el": "Διαχειριστής Καταστήματος"},
    {"value": "staff_manager",    "label": "Staff Manager",      "label_el": "Διαχειριστής Προσωπικού"},
    {"value": "chef",             "label": "Chef",               "label_el": "Σεφ"},
    {"value": "assistant_chef",   "label": "Assistant Chef",     "label_el": "Βοηθός Σεφ"},
    {"value": "barista",          "label": "Barista",            "label_el": "Barista"},
    {"value": "barman",           "label": "Barman / Barwoman",  "label_el": "Barman / Barwoman"},
    {"value": "waiter",           "label": "Waiter",             "label_el": "Σερβιτόρος"},
    {"value": "assistant_waiter", "label": "Assistant Waiter",   "label_el": "Βοηθός Σερβιτόρου"},
    {"value": "custom",           "label": "Custom",             "label_el": "Προσαρμοσμένος"},
]

VALID_ROLES: set[str] = {r["value"] for r in ALL_ROLES}

# Roles that have manager-level dashboard access by default
MANAGER_ROLES: set[str] = {"superadmin", "owner", "store_manager", "staff_manager"}

# Full permission set — what a superadmin always has
_ALL_ON = dict(
    perm_access_dashboard=True,
    perm_access_waiter_app=True,
    perm_access_kds=True,
    perm_cancel_orders=True,
    perm_apply_discounts=True,
    perm_modify_prices=True,
    perm_open_orders=True,
    perm_close_orders=True,
    perm_view_reports=True,
    perm_manage_staff=True,
    perm_manage_tables=True,
    perm_manage_menu=True,
    perm_manage_settings=True,
)

_ALL_OFF = {k: False for k in _ALL_ON}

# Default permissions keyed by role value.
# These are applied at creation time and on "Reset to defaults".
DEFAULT_PERMISSIONS: dict[str, dict] = {
    "superadmin": _ALL_ON,
    "owner": dict(
        perm_access_dashboard=True,
        perm_access_waiter_app=True,
        perm_access_kds=True,
        perm_cancel_orders=True,
        perm_apply_discounts=True,
        perm_modify_prices=True,
        perm_open_orders=True,
        perm_close_orders=True,
        perm_view_reports=True,
        perm_manage_staff=True,
        perm_manage_tables=True,
        perm_manage_menu=True,
        perm_manage_settings=True,
    ),
    "store_manager": dict(
        perm_access_dashboard=True,
        perm_access_waiter_app=True,
        perm_access_kds=True,
        perm_cancel_orders=True,
        perm_apply_discounts=True,
        perm_modify_prices=False,
        perm_open_orders=True,
        perm_close_orders=True,
        perm_view_reports=True,
        perm_manage_staff=True,
        perm_manage_tables=True,
        perm_manage_menu=True,
        perm_manage_settings=False,
    ),
    "staff_manager": dict(
        perm_access_dashboard=True,
        perm_access_waiter_app=True,
        perm_access_kds=False,
        perm_cancel_orders=False,
        perm_apply_discounts=False,
        perm_modify_prices=False,
        perm_open_orders=False,
        perm_close_orders=False,
        perm_view_reports=True,
        perm_manage_staff=True,
        perm_manage_tables=False,
        perm_manage_menu=False,
        perm_manage_settings=False,
    ),
    "chef": dict(
        perm_access_dashboard=False,
        perm_access_waiter_app=False,
        perm_access_kds=True,
        perm_cancel_orders=False,
        perm_apply_discounts=False,
        perm_modify_prices=False,
        perm_open_orders=False,
        perm_close_orders=False,
        perm_view_reports=False,
        perm_manage_staff=False,
        perm_manage_tables=False,
        perm_manage_menu=False,
        perm_manage_settings=False,
    ),
    "assistant_chef": dict(
        perm_access_dashboard=False,
        perm_access_waiter_app=False,
        perm_access_kds=True,
        perm_cancel_orders=False,
        perm_apply_discounts=False,
        perm_modify_prices=False,
        perm_open_orders=False,
        perm_close_orders=False,
        perm_view_reports=False,
        perm_manage_staff=False,
        perm_manage_tables=False,
        perm_manage_menu=False,
        perm_manage_settings=False,
    ),
    "barista": dict(
        perm_access_dashboard=False,
        perm_access_waiter_app=True,
        perm_access_kds=False,
        perm_cancel_orders=False,
        perm_apply_discounts=False,
        perm_modify_prices=False,
        perm_open_orders=True,
        perm_close_orders=True,
        perm_view_reports=False,
        perm_manage_staff=False,
        perm_manage_tables=False,
        perm_manage_menu=False,
        perm_manage_settings=False,
    ),
    "barman": dict(
        perm_access_dashboard=False,
        perm_access_waiter_app=True,
        perm_access_kds=False,
        perm_cancel_orders=False,
        perm_apply_discounts=False,
        perm_modify_prices=False,
        perm_open_orders=True,
        perm_close_orders=True,
        perm_view_reports=False,
        perm_manage_staff=False,
        perm_manage_tables=False,
        perm_manage_menu=False,
        perm_manage_settings=False,
    ),
    "waiter": dict(
        perm_access_dashboard=False,
        perm_access_waiter_app=True,
        perm_access_kds=False,
        perm_cancel_orders=False,
        perm_apply_discounts=False,
        perm_modify_prices=False,
        perm_open_orders=True,
        perm_close_orders=True,
        perm_view_reports=False,
        perm_manage_staff=False,
        perm_manage_tables=False,
        perm_manage_menu=False,
        perm_manage_settings=False,
    ),
    "assistant_waiter": dict(
        perm_access_dashboard=False,
        perm_access_waiter_app=True,
        perm_access_kds=False,
        perm_cancel_orders=False,
        perm_apply_discounts=False,
        perm_modify_prices=False,
        perm_open_orders=False,
        perm_close_orders=False,
        perm_view_reports=False,
        perm_manage_staff=False,
        perm_manage_tables=False,
        perm_manage_menu=False,
        perm_manage_settings=False,
    ),
    "custom": _ALL_OFF,
}


def get_default_permissions(role: str) -> dict:
    """Return default permission values for a given role."""
    return DEFAULT_PERMISSIONS.get(role, _ALL_OFF).copy()


def is_manager_role(role: str) -> bool:
    return role in MANAGER_ROLES
