/** Loyalty permission catalog — mirrors backend permissions/definitions.py (no HTTP API). */
export const LOYALTY_PERMISSIONS = [
  "loyalty.view",
  "loyalty.manage",
  "loyalty.programs.view",
  "loyalty.programs.create",
  "loyalty.programs.update",
  "loyalty.programs.delete",
  "loyalty.programs.manage",
  "loyalty.tiers.view",
  "loyalty.tiers.create",
  "loyalty.tiers.update",
  "loyalty.tiers.delete",
  "loyalty.tiers.manage",
  "loyalty.members.view",
  "loyalty.members.create",
  "loyalty.members.update",
  "loyalty.members.delete",
  "loyalty.members.manage",
  "loyalty.members.enroll",
  "loyalty.members.activate",
  "loyalty.members.renew",
  "loyalty.members.freeze",
  "loyalty.members.resume",
  "loyalty.members.cancel",
  "loyalty.members.expire",
  "loyalty.members.transfer",
  "loyalty.members.lifecycle.view",
  "loyalty.point_accounts.view",
  "loyalty.point_accounts.create",
  "loyalty.point_accounts.update",
  "loyalty.point_accounts.manage",
  "loyalty.points.view",
  "loyalty.points.earn",
  "loyalty.points.redeem",
  "loyalty.points.adjust",
  "loyalty.points.expire",
  "loyalty.points.manage",
  "loyalty.rewards.view",
  "loyalty.rewards.create",
  "loyalty.rewards.update",
  "loyalty.rewards.delete",
  "loyalty.rewards.manage",
  "loyalty.rewards.redeem",
  "loyalty.rewards.fulfill",
  "loyalty.rewards.cancel",
  "loyalty.redemptions.view",
  "loyalty.campaigns.view",
  "loyalty.campaigns.create",
  "loyalty.campaigns.update",
  "loyalty.campaigns.delete",
  "loyalty.campaigns.manage",
  "loyalty.campaigns.schedule",
  "loyalty.campaigns.activate",
  "loyalty.campaigns.pause",
  "loyalty.campaigns.resume",
  "loyalty.campaigns.expire",
  "loyalty.campaigns.apply",
  "loyalty.campaigns.rules.update",
  "loyalty.campaigns.applications.view",
  "loyalty.referral_programs.view",
  "loyalty.referral_programs.create",
  "loyalty.referral_programs.update",
  "loyalty.referral_programs.delete",
  "loyalty.referral_programs.manage",
  "loyalty.referral_codes.view",
  "loyalty.referral_codes.create",
  "loyalty.referral_codes.revoke",
  "loyalty.referral_codes.manage",
  "loyalty.referrals.view",
  "loyalty.referrals.attribute",
  "loyalty.referrals.convert",
  "loyalty.referrals.reward",
  "loyalty.referrals.cancel",
  "loyalty.referrals.manage",
  "loyalty.wallets.view",
  "loyalty.wallets.create",
  "loyalty.wallets.credit",
  "loyalty.wallets.debit",
  "loyalty.wallets.adjust",
  "loyalty.wallets.transfer",
  "loyalty.wallets.delete",
  "loyalty.wallets.manage",
  "loyalty.audit.view",
] as const;

export type LoyaltyPermission = (typeof LOYALTY_PERMISSIONS)[number];

export const LOYALTY_PERMISSION_GROUPS: { label: string; permissions: LoyaltyPermission[] }[] = [
  {
    label: "برنامه‌های وفاداری",
    permissions: LOYALTY_PERMISSIONS.filter((p) =>
      p.startsWith("loyalty.programs.")
    ) as LoyaltyPermission[],
  },
  {
    label: "سطوح عضویت",
    permissions: LOYALTY_PERMISSIONS.filter((p) =>
      p.startsWith("loyalty.tiers.")
    ) as LoyaltyPermission[],
  },
  {
    label: "اعضا",
    permissions: LOYALTY_PERMISSIONS.filter((p) =>
      p.startsWith("loyalty.members.")
    ) as LoyaltyPermission[],
  },
  {
    label: "حساب و امتیاز",
    permissions: LOYALTY_PERMISSIONS.filter(
      (p) => p.startsWith("loyalty.point_accounts.") || p.startsWith("loyalty.points.")
    ) as LoyaltyPermission[],
  },
  {
    label: "پاداش و استفاده",
    permissions: LOYALTY_PERMISSIONS.filter(
      (p) => p.startsWith("loyalty.rewards.") || p.startsWith("loyalty.redemptions.")
    ) as LoyaltyPermission[],
  },
  {
    label: "کمپین‌ها",
    permissions: LOYALTY_PERMISSIONS.filter((p) =>
      p.startsWith("loyalty.campaigns.")
    ) as LoyaltyPermission[],
  },
  {
    label: "معرفی و ارجاع",
    permissions: LOYALTY_PERMISSIONS.filter(
      (p) => p.startsWith("loyalty.referral_programs.") ||
        p.startsWith("loyalty.referral_codes.") ||
        p.startsWith("loyalty.referrals.")
    ) as LoyaltyPermission[],
  },
  {
    label: "کیف پول",
    permissions: LOYALTY_PERMISSIONS.filter((p) =>
      p.startsWith("loyalty.wallets.")
    ) as LoyaltyPermission[],
  },
  {
    label: "ممیزی",
    permissions: LOYALTY_PERMISSIONS.filter((p) =>
      p.startsWith("loyalty.audit.")
    ) as LoyaltyPermission[],
  },
];
