import * as yup from 'yup';

export type TransferToLayingFilterType = {
  startDate: string | null;
  endDate: string | null;
  flockSource: number[];
  flockDestination: number[];
  status: string[];
};

export const TransferToLayingFilterSchema = yup.object({
  startDate: yup.string().optional().nullable(),
  endDate: yup
    .string()
    .optional()
    .nullable()
    .test(
      'is-greater-than-start',
      'Tanggal akhir tidak boleh masa lampau',
      function (value) {
        const { startDate } = this.parent;
        if (!startDate || !value) return true;
        return new Date(value) >= new Date(startDate);
      }
    ),
  flockSource: yup.array().optional().nullable(),
  flockDestination: yup.array().optional().nullable(),
  status: yup.array().optional().nullable(),
});

export type TransferToLayingFilterValues = yup.InferType<
  typeof TransferToLayingFilterSchema
>;
