import * as yup from 'yup';

export type CustomerPaymentFilterType = {
  start_date: string | null;
  end_date: string | null;
  customer_ids: string | null;
  filter_by: string | null;
};

export const CustomerPaymentFilterSchema = yup.object({
  start_date: yup.string().optional().nullable(),
  end_date: yup
    .string()
    .optional()
    .nullable()
    .test(
      'is-greater-than-start',
      'Tanggal akhir tidak boleh masa lampau',
      function (value) {
        const { start_date } = this.parent;
        if (!start_date || !value) return true;
        return new Date(value) >= new Date(start_date);
      }
    ),
  customer_ids: yup.string().nullable(),
  filter_by: yup.string().nullable(),
});

export type CustomerPaymentFilterValues = yup.InferType<
  typeof CustomerPaymentFilterSchema
>;
