import { z } from 'zod';
import { UserRole, UserStatus } from '@prisma/client';

export const createUserSchema = z.object({
  email: z.string().email(),
  password: z.string()
    .min(12, 'Password must be at least 12 characters')
    .regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
    .regex(/[a-z]/, 'Password must contain at least one lowercase letter')
    .regex(/[0-9]/, 'Password must contain at least one digit'),
  name: z.string().optional(),
  phone: z.string().optional(),
  pronouns: z.string().max(50).optional(),
  role: z.nativeEnum(UserRole).optional(),
  roles: z.array(z.nativeEnum(UserRole)).optional(),
  status: z.nativeEnum(UserStatus).optional(),
  expiresAt: z.string().datetime().optional(),
  expireDays: z.number().int().positive().optional(),
});

export const updateUserSchema = z.object({
  email: z.string().email().optional(),
  password: z.string()
    .min(12, 'Password must be at least 12 characters')
    .regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
    .regex(/[a-z]/, 'Password must contain at least one lowercase letter')
    .regex(/[0-9]/, 'Password must contain at least one digit')
    .optional(),
  name: z.string().optional(),
  phone: z.string().optional(),
  pronouns: z.string().max(50).nullable().optional(),
  role: z.nativeEnum(UserRole).optional(),
  roles: z.array(z.nativeEnum(UserRole)).optional(),
  status: z.nativeEnum(UserStatus).optional(),
  expiresAt: z.string().datetime().nullable().optional(),
  expireDays: z.number().int().positive().nullable().optional(),
});

export const listUsersSchema = z.object({
  page: z.coerce.number().int().positive().default(1),
  limit: z.coerce.number().int().positive().max(100).default(20),
  search: z.string().optional(),
  role: z.nativeEnum(UserRole).optional(),
  status: z.nativeEnum(UserStatus).optional(),
});

export type CreateUserInput = z.infer<typeof createUserSchema>;
export type UpdateUserInput = z.infer<typeof updateUserSchema>;
export type ListUsersInput = z.infer<typeof listUsersSchema>;
