import { z } from 'zod';
import { BUSINESS_ROLES } from '@/lib/auth/rbac';

export const APPROVAL_MODES = ['sequential', 'any_one', 'all_required'] as const;

export const approvalStepSchema = z.object({
  stepNumber: z.number().int().min(1),
  roleCode: z.enum(BUSINESS_ROLES),
  roleName: z.string().trim().min(1),
  approvalMode: z.enum(APPROVAL_MODES).default('sequential'),
  isRequired: z.boolean().default(true)
});

export const createApprovalStepSchema = approvalStepSchema;

export const updateApprovalStepSchema = z.object({
  roleCode: z.enum(BUSINESS_ROLES).optional(),
  roleName: z.string().trim().min(1).optional(),
  approvalMode: z.enum(APPROVAL_MODES).optional(),
  isRequired: z.boolean().optional()
});

export const reorderApprovalStepsSchema = z.object({
  orderedStepIds: z.array(z.string().min(1)).min(1)
});

export type CreateApprovalStepInput = z.infer<typeof createApprovalStepSchema>;
export type UpdateApprovalStepInput = z.infer<typeof updateApprovalStepSchema>;
export type ReorderApprovalStepsInput = z.infer<typeof reorderApprovalStepsSchema>;
