/**
 * Built-in SMARTPOS permissions (technical `name` is used by the API).
 * Seeded on startup — admins pick from this list when configuring roles.
 */
const PERMISSION_CATALOG = [
  {
    name: "pos:read",
    label: "View sales & customers",
    category: "Point of sale",
    sortOrder: 10,
    description:
      "View POS checkout, sales, purchases, returns, invoices, customers, suppliers, expenses, and payment methods. Does not allow completing sales or editing records.",
  },
  {
    name: "pos:write",
    label: "Manage sales & customers",
    category: "Point of sale",
    sortOrder: 20,
    description:
      "Create and edit sales, complete checkout, hold drafts, and manage customers, suppliers, purchases, invoices, expenses, and payment methods.",
  },
  {
    name: "inventory:read",
    label: "View inventory",
    category: "Inventory",
    sortOrder: 30,
    description:
      "View products, categories, brands, units, taxes, variations, warehouses, stock adjustments, transfers, and print barcodes. Read-only access to stock data.",
  },
  {
    name: "inventory:write",
    label: "Manage inventory",
    category: "Inventory",
    sortOrder: 40,
    description:
      "Add, edit, and delete products and catalog data (categories, brands, units, taxes, variations), manage warehouses, adjustments, and stock transfers.",
  },
  {
    name: "admin:*",
    label: "Branch administration",
    category: "Administration",
    sortOrder: 50,
    description:
      "Manage branches and see all branches in the system. Required for multi-branch setup and assigning users to branches.",
  },
];

const SYSTEM_PERMISSION_NAMES = PERMISSION_CATALOG.map((p) => p.name);

function isSystemPermissionName(name) {
  return SYSTEM_PERMISSION_NAMES.includes(name);
}

module.exports = {
  PERMISSION_CATALOG,
  SYSTEM_PERMISSION_NAMES,
  isSystemPermissionName,
};
