import { z } from "zod";

const email = z.string().trim().toLowerCase().email().max(255);
const otpCode = z
  .string()
  .trim()
  .regex(/^\d{6}$/, "OTP must be a 6 digit code");
const password = z
  .string()
  .min(8, "Password must be at least 8 characters")
  .max(72, "Password must be 72 characters or fewer")
  .regex(/[A-Z]/, "Password must include at least one uppercase letter")
  .regex(/[a-z]/, "Password must include at least one lowercase letter")
  .regex(/[0-9]/, "Password must include at least one number");

export const customerRequestOtpSchema = z.object({
  email,
});

export const customerVerifyOtpSchema = z.object({
  email,
  code: otpCode,
  name: z.string().trim().min(1).max(255).optional(),
  phoneNumber: z.string().trim().min(7).max(30).optional(),
});

export const staffRegisterSchema = z.object({
  name: z.string().trim().min(2).max(255),
  email,
  password,
  role: z.enum(["seller", "admin"]).default("seller"),
});

export const staffLoginSchema = z.object({
  email,
  password: z.string().min(1).max(72),
});

export const staffRequestOtpSchema = z.object({
  email,
});

export const staffVerifyOtpSchema = z.object({
  email,
  code: otpCode,
});

export const refreshTokenSchema = z.object({
  refreshToken: z.string().trim().min(64).max(256),
});

export const changePasswordSchema = z.object({
  currentPassword: z.string().min(1, "Current password is required").max(72),
  newPassword: password,
});

export const logoutSchema = z.object({
  refreshToken: z.string().trim().min(64).max(256),
});

export const customerUpdateProfileSchema = z.object({
  name: z.string().trim().min(1).max(255).optional(),
  phoneNumber: z.string().trim().min(7).max(30).optional(),
});
