import { z } from 'zod';

/** Shared password rules — reused by create, self-change, and admin-reset paths. */
export const PasswordSchema = z.string().min(8).max(128);

export const CreateUserSchema = z.object({
  email: z.string().email(),
  password: PasswordSchema,
  name: z.string().max(100).optional(),
});

export const UpdateUserSchema = z.object({
  name: z.string().max(100).optional(),
  password: PasswordSchema.optional(),
});

/** Self-service change: requires the current password as proof. */
export const ChangeOwnPasswordSchema = z.object({
  currentPassword: z.string().min(1),
  newPassword: PasswordSchema,
});

/** Admin reset of another user: no current password needed. */
export const ResetPasswordSchema = z.object({
  newPassword: PasswordSchema,
});

export type CreateUserInput = z.infer<typeof CreateUserSchema>;
export type UpdateUserInput = z.infer<typeof UpdateUserSchema>;
