import { z } from 'zod';

export const createUserSchema = z.object({
  email: z.string().email(),
  name: z.string().min(1).max(200),
  password: z.string().min(12),
  displayName: z.string().min(1).max(200),
  firstName: z.string().min(1).max(200).nullable().optional(),
  lastName: z.string().min(1).max(200).nullable().optional(),
  phone: z.string().optional(),
  roleId: z.string().uuid(),
  residentialAccess: z.boolean().optional().default(false),
});

export type CreateUserInput = z.infer<typeof createUserSchema>;

export const updateUserSchema = z.object({
  displayName: z.string().min(1).max(200).optional(),
  firstName: z.string().min(1).max(200).nullable().optional(),
  lastName: z.string().min(1).max(200).nullable().optional(),
  fullName: z.string().min(1).max(400).optional(),
  /** Admin-initiated email change. When changed, the original address
   *  receives an automated heads-up email (see notifyEmailChange). */
  email: z.string().email().optional(),
  /** Set true alongside `email` to send the "your admin changed your
   *  sign-in email" notification to the prior address. UI sets this when
   *  the admin confirms the warning dialog. */
  notifyEmailChange: z.boolean().optional(),
  phone: z.string().nullable().optional(),
  isActive: z.boolean().optional(),
  roleId: z.string().uuid().optional(),
  residentialAccess: z.boolean().optional(),
});

export type UpdateUserInput = z.infer<typeof updateUserSchema>;

export const resetPasswordSchema = z.object({
  newPassword: z.string().min(12),
});

export type ResetPasswordInput = z.infer<typeof resetPasswordSchema>;
