/** CRM permission catalog — mirrors backend definitions.py (no HTTP API). */
export const CRM_PERMISSIONS = [
  "crm.view",
  "crm.manage",
  "crm.leads.view",
  "crm.leads.create",
  "crm.leads.update",
  "crm.leads.delete",
  "crm.leads.manage",
  "crm.leads.assign",
  "crm.contacts.view",
  "crm.contacts.create",
  "crm.contacts.update",
  "crm.contacts.delete",
  "crm.contacts.manage",
  "crm.organizations.view",
  "crm.organizations.create",
  "crm.organizations.update",
  "crm.organizations.delete",
  "crm.organizations.manage",
  "crm.opportunities.view",
  "crm.opportunities.create",
  "crm.opportunities.update",
  "crm.opportunities.delete",
  "crm.opportunities.manage",
  "crm.opportunities.win",
  "crm.pipelines.view",
  "crm.pipelines.create",
  "crm.pipelines.update",
  "crm.pipelines.delete",
  "crm.pipelines.manage",
  "crm.activities.view",
  "crm.activities.create",
  "crm.activities.update",
  "crm.activities.delete",
  "crm.activities.manage",
  "crm.activities.complete",
  "crm.tasks.view",
  "crm.tasks.create",
  "crm.tasks.update",
  "crm.tasks.delete",
  "crm.tasks.manage",
  "crm.tasks.complete",
  "crm.meetings.view",
  "crm.meetings.create",
  "crm.meetings.update",
  "crm.meetings.delete",
  "crm.meetings.manage",
  "crm.calls.view",
  "crm.calls.create",
  "crm.calls.update",
  "crm.calls.manage",
  "crm.timeline.view",
  "crm.timeline.manage",
  "crm.comments.view",
  "crm.comments.create",
  "crm.comments.update",
  "crm.comments.delete",
  "crm.comments.manage",
  "crm.mentions.view",
  "crm.mentions.create",
  "crm.mentions.manage",
  "crm.team.view",
  "crm.team.create",
  "crm.team.update",
  "crm.team.manage",
  "crm.quotes.view",
  "crm.quotes.create",
  "crm.quotes.update",
  "crm.quotes.delete",
  "crm.quotes.manage",
  "crm.notes.view",
  "crm.notes.create",
  "crm.notes.update",
  "crm.notes.delete",
  "crm.notes.manage",
  "crm.attachments.view",
  "crm.attachments.create",
  "crm.attachments.delete",
  "crm.attachments.manage",
  "crm.customfields.view",
  "crm.customfields.create",
  "crm.customfields.update",
  "crm.customfields.manage",
] as const;

export type CrmPermission = (typeof CRM_PERMISSIONS)[number];

export const CRM_PERMISSION_GROUPS: { label: string; permissions: CrmPermission[] }[] = [
  {
    label: "سرنخ‌ها",
    permissions: CRM_PERMISSIONS.filter((p) => p.startsWith("crm.leads.")) as CrmPermission[],
  },
  {
    label: "مخاطبین",
    permissions: CRM_PERMISSIONS.filter((p) => p.startsWith("crm.contacts.")) as CrmPermission[],
  },
  {
    label: "سازمان‌ها",
    permissions: CRM_PERMISSIONS.filter((p) =>
      p.startsWith("crm.organizations.")
    ) as CrmPermission[],
  },
  {
    label: "فرصت‌ها",
    permissions: CRM_PERMISSIONS.filter((p) =>
      p.startsWith("crm.opportunities.")
    ) as CrmPermission[],
  },
  {
    label: "همکاری",
    permissions: CRM_PERMISSIONS.filter(
      (p) =>
        p.startsWith("crm.tasks.") ||
        p.startsWith("crm.meetings.") ||
        p.startsWith("crm.calls.") ||
        p.startsWith("crm.timeline.") ||
        p.startsWith("crm.comments.") ||
        p.startsWith("crm.mentions.") ||
        p.startsWith("crm.team.")
    ) as CrmPermission[],
  },
];
