import { OptionType } from '@/components/input/SelectInput';
import * as yup from 'yup';

export type ReportExpenseFilterProps = {
  location_id: string | null;
  supplier_id: string | null;
  kandang_id: string | null;
  nonstock_id: string | null;
  realization_date: string | null;
  category: string | null;
};

export type ReportExpenseFilterFormType = {
  location_id: OptionType | null;
  supplier_id: OptionType | null;
  kandang_id: OptionType | null;
  nonstock_id: OptionType | null;
  realization_date: string | null;
  category: OptionType | null;
};

export const ReportExpenseFilterSchema = yup.object({
  location_id: yup
    .mixed<OptionType>()
    .nullable()
    .test('is-not-empty', 'Lokasi wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return true;
    }),
  supplier_id: yup
    .mixed<OptionType>()
    .nullable()
    .test('is-not-empty', 'Supplier wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return true;
    }),
  kandang_id: yup
    .mixed<OptionType>()
    .nullable()
    .test('is-not-empty', 'Kandang wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return true;
    }),
  nonstock_id: yup
    .mixed<OptionType>()
    .nullable()
    .test('is-not-empty', 'Produk wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return true;
    }),
  realization_date: yup.string().nullable(),
  category: yup
    .mixed<OptionType>()
    .nullable()
    .test('is-not-empty', 'Kategori wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return true;
    }),
}) as yup.ObjectSchema<ReportExpenseFilterFormType>;

export type ReportExpenseFilterValues = yup.InferType<
  typeof ReportExpenseFilterSchema
>;
