/**
 * @ai-summary Request validation schemas for admin API
 * @ai-context Uses Zod for runtime validation and type safety
 */

import { z } from 'zod';

export const createAdminSchema = z.object({
  email: z.string().email('Invalid email format'),
  role: z.enum(['admin', 'super_admin']).default('admin'),
});

export const adminAuth0SubSchema = z.object({
  auth0Sub: z.string().min(1, 'auth0Sub is required'),
});

export const auditLogsQuerySchema = z.object({
  limit: z.coerce.number().min(1).max(1000).default(100),
  offset: z.coerce.number().min(0).default(0),
});

export const bulkCreateAdminSchema = z.object({
  admins: z.array(
    z.object({
      email: z.string().email('Invalid email format'),
      role: z.enum(['admin', 'super_admin']).optional().default('admin'),
    })
  ).min(1, 'At least one admin must be provided').max(100, 'Maximum 100 admins per batch'),
});

export const bulkRevokeAdminSchema = z.object({
  auth0Subs: z.array(z.string().min(1, 'auth0Sub cannot be empty'))
    .min(1, 'At least one auth0Sub must be provided')
    .max(100, 'Maximum 100 admins per batch'),
});

export const bulkReinstateAdminSchema = z.object({
  auth0Subs: z.array(z.string().min(1, 'auth0Sub cannot be empty'))
    .min(1, 'At least one auth0Sub must be provided')
    .max(100, 'Maximum 100 admins per batch'),
});

export const catalogEntitySchema = z.enum(['makes', 'models', 'years', 'trims', 'engines']);

export const bulkDeleteCatalogSchema = z.object({
  ids: z.array(z.number().int().positive('ID must be a positive integer'))
    .min(1, 'At least one ID must be provided')
    .max(100, 'Maximum 100 items per batch'),
});

export type CreateAdminInput = z.infer<typeof createAdminSchema>;
export type AdminAuth0SubInput = z.infer<typeof adminAuth0SubSchema>;
export type AuditLogsQueryInput = z.infer<typeof auditLogsQuerySchema>;
export type BulkCreateAdminInput = z.infer<typeof bulkCreateAdminSchema>;
export type BulkRevokeAdminInput = z.infer<typeof bulkRevokeAdminSchema>;
export type BulkReinstateAdminInput = z.infer<typeof bulkReinstateAdminSchema>;
export type CatalogEntity = z.infer<typeof catalogEntitySchema>;
export type BulkDeleteCatalogInput = z.infer<typeof bulkDeleteCatalogSchema>;
