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

export type ProductionResultFilterProps = {
  area_id: string | null;
  location_id: string | null;
  project_flock_id: string | null;
  kandang_id: string | null;
};

export type ProductionResultFilterFormType = {
  area_id: OptionType | null;
  location_id: OptionType | null;
  project_flock_id: OptionType | null;
  kandang_id: OptionType | null;
};

export const ProductionResultFilterSchema = yup.object({
  area_id: yup
    .mixed<OptionType>()
    .required('Area wajib dipilih')
    .test('is-not-empty', 'Area wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return !!value;
    }),
  location_id: yup
    .mixed<OptionType>()
    .required('Lokasi wajib dipilih')
    .test('is-not-empty', 'Lokasi wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return !!value;
    }),
  project_flock_id: yup
    .mixed<OptionType>()
    .required('Project Flock wajib dipilih')
    .test('is-not-empty', 'Project Flock wajib dipilih', (value) => {
      if (Array.isArray(value)) {
        return value.length > 0;
      }
      return !!value;
    }),
  kandang_id: yup.mixed<OptionType>().nullable(),
}) as yup.ObjectSchema<ProductionResultFilterFormType>;

export type ProductionResultFilterValues = yup.InferType<
  typeof ProductionResultFilterSchema
>;
