import * as yup from 'yup';

export const bookingValidationSchema = yup.object().shape({
  checkInDate: yup
    .date()
    .required('Please select check-in date')
    .min(
      new Date(new Date().setHours(0, 0, 0, 0)),
      'Check-in date cannot be in the past'
    )
    .typeError('Invalid check-in date'),

  checkOutDate: yup
    .date()
    .required('Please select check-out date')
    .min(
      yup.ref('checkInDate'),
      'Check-out date must be after check-in date'
    )
    .typeError('Invalid check-out date'),

  guestCount: yup
    .number()
    .required('Please enter number of guests')
    .min(1, 'Minimum number of guests is 1')
    .max(10, 'Maximum number of guests is 10')
    .integer('Number of guests must be an integer')
    .typeError('Number of guests must be a number'),

  notes: yup
    .string()
    .max(500, 'Notes cannot exceed 500 characters')
    .optional(),

  paymentMethod: yup
    .mixed<'cash' | 'stripe' | 'paypal'>()
    .required('Please select payment method')
    .oneOf(
      ['cash', 'stripe', 'paypal'],
      'Invalid payment method'
    ),

  fullName: yup
    .string()
    .required('Please enter full name')
    .min(2, 'Full name must be at least 2 characters')
    .max(100, 'Full name cannot exceed 100 characters'),

  email: yup
    .string()
    .required('Please enter email')
    .email('Invalid email'),

  phone: yup
    .string()
    .required('Please enter phone number')
    .matches(
      /^[\d\s\-+()]{5,}$/,
      'Please enter a valid phone number'
    ),
});

export type BookingFormData = yup.InferType<
  typeof bookingValidationSchema
>;
