import { z } from 'zod';

export const loginSchema = z.object({
  email: z
    .string()
    .min(1, 'Email is required')
    .email('Please enter a valid email address')
    .max(254, 'Email address is too long'),
  password: z
    .string()
    .min(1, 'Password is required')
    .max(128, 'Password is too long'),
  remember_me: z.boolean().optional().default(false),
  subdomain: z.string().optional(),
});

export const forgotPasswordSchema = z.object({
  identifier: z
    .string()
    .min(1, 'Email or phone number is required')
    .max(254, 'Value is too long'),
  channel: z.enum(['email', 'sms']).default('sms'),
});

export const verifyOtpSchema = z.object({
  otp: z
    .string()
    .min(4, 'Verification code must be at least 4 characters')
    .max(8, 'Verification code is too long')
    .regex(/^\d+$/, 'Verification code must contain digits only'),
});

export const resetPasswordSchema = z
  .object({
    password: z
      .string()
      .min(8, 'Password must be at least 8 characters')
      .max(128, 'Password is too long')
      .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 number'),
    password_confirmation: z.string().min(1, 'Please confirm your password'),
  })
  .refine((data) => data.password === data.password_confirmation, {
    message: 'Passwords do not match',
    path: ['password_confirmation'],
  });

export type LoginInput = z.infer<typeof loginSchema>;
export type ForgotPasswordInput = z.infer<typeof forgotPasswordSchema>;
export type VerifyOtpInput = z.infer<typeof verifyOtpSchema>;
export type ResetPasswordInput = z.infer<typeof resetPasswordSchema>;
