import { z } from 'zod';

const permissionGroupSchema = z.record(z.string(), z.boolean());

const rolePermissionsSchema = z.object({
  clients: permissionGroupSchema,
  interests: permissionGroupSchema,
  berths: permissionGroupSchema,
  documents: permissionGroupSchema,
  expenses: permissionGroupSchema,
  invoices: permissionGroupSchema,
  payments: permissionGroupSchema,
  files: permissionGroupSchema,
  email: permissionGroupSchema,
  reminders: permissionGroupSchema,
  calendar: permissionGroupSchema,
  reports: permissionGroupSchema,
  document_templates: permissionGroupSchema,
  admin: permissionGroupSchema,
});

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

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

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

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