import { z } from 'zod';

const CANONICAL_SECTIONS = ['dashboard', 'orders', 'reservations', 'menu', 'customers', 'conversations', 'staff', 'analytics', 'settings'] as const;

const crudPermsSchema = z.object({
  create: z.boolean(),
  read: z.boolean(),
  update: z.boolean(),
  delete: z.boolean(),
});

export const permissionsMapSchema = z.object({
  dashboard: crudPermsSchema,
  orders: crudPermsSchema,
  reservations: crudPermsSchema,
  menu: crudPermsSchema,
  customers: crudPermsSchema,
  conversations: crudPermsSchema,
  staff: crudPermsSchema,
  analytics: crudPermsSchema,
  settings: crudPermsSchema,
}).strict();

export const createRoleSchema = z.object({
  name: z.string().min(1, 'Role name is required').max(100),
  description: z.string().max(500).optional(),
  permissions: permissionsMapSchema,
});

export const updateRoleSchema = z.object({
  name: z.string().min(1).max(100).optional(),
  description: z.string().max(500).optional(),
  permissions: permissionsMapSchema.optional(),
});

export type CreateRoleInput = z.infer<typeof createRoleSchema>;
export type UpdateRoleInput = z.infer<typeof updateRoleSchema>;

export { CANONICAL_SECTIONS };
