import * as yup from 'yup';

export const loginSchema = yup.object().shape({
  email: yup
    .string()
    .required('Email is required')
    .email('Invalid email')
    .trim(),
  password: yup
    .string()
    .required('Password is required')
    .min(8, 'Password must be at least 8 characters'),
  rememberMe: yup
    .boolean()
    .optional(),
});

export const registerSchema = yup.object().shape({
  name: yup
    .string()
    .required('Full name is required')
    .min(2, 'Full name must be at least 2 characters')
    .max(50, 'Full name must not exceed 50 characters')
    .trim(),
  email: yup
    .string()
    .required('Email is required')
    .email('Invalid email')
    .trim(),
  password: yup
    .string()
    .required('Password is required')
    .min(8, 'Password must be at least 8 characters')
    .matches(
      /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])/,
      'Password must contain uppercase, lowercase, ' +
      'number and special character'
    ),
  confirmPassword: yup
    .string()
    .required('Please confirm password')
    .oneOf([yup.ref('password')], 'Passwords do not match'),
  phone: yup
    .string()
    .optional()
    .matches(
      /^[\d\s\-\+\(\)]{5,}$/,
      'Please enter a valid phone number'
    ),
});

export const forgotPasswordSchema = yup.object().shape({
  email: yup
    .string()
    .required('Email is required')
    .email('Invalid email')
    .trim(),
});

export const resetPasswordSchema = yup.object().shape({
  password: yup
    .string()
    .required('New password is required')
    .min(8, 'Password must be at least 8 characters')
    .matches(
      /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])/,
      'Password must contain uppercase, lowercase, ' +
      'number and special character'
    ),
  confirmPassword: yup
    .string()
    .required('Please confirm password')
    .oneOf([yup.ref('password')], 'Passwords do not match'),
});

export type LoginFormData = yup.InferType<typeof loginSchema>;
export type RegisterFormData = 
  yup.InferType<typeof registerSchema>;
export type ForgotPasswordFormData = 
  yup.InferType<typeof forgotPasswordSchema>;
export type ResetPasswordFormData = 
  yup.InferType<typeof resetPasswordSchema>;
