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

type KandangFormSchemaType = {
  name: string;
  locationId: number | undefined;
  location:
    | {
        value: number;
        label: string;
      }
    | undefined
    | null;
  capacity: number | undefined;
  picId: number | undefined;
  pic:
    | {
        value: number;
        label: string;
      }
    | undefined
    | null;
  group?: OptionType;
};

export const KandangFormSchema: Yup.ObjectSchema<KandangFormSchemaType> =
  Yup.object({
    name: Yup.string().required('Nama wajib diisi!'),

    locationId: Yup.number()
      .min(1, 'Lokasi wajib diisi!')
      .required('Lokasi wajib diisi!'),
    location: Yup.object({
      value: Yup.number().min(1).required(),
      label: Yup.string().required(),
    }).nullable(),

    capacity: Yup.number()
      .min(1, 'Kapasitas wajib diisi!')
      .required('Kapasitas wajib diisi!'),

    picId: Yup.number().min(1, 'PIC wajib diisi!').required('PIC wajib diisi!'),
    pic: Yup.object({
      value: Yup.number().min(1).required(),
      label: Yup.string().required(),
    }).nullable(),

    group: Yup.object({
      value: Yup.number().min(1).required('Kandang Grup wajib diisi!'),
      label: Yup.string().required('Kandang Grup wajib diisi!'),
    }).required('Kandang Grup wajib diisi!'),
  });

export const UpdateKandangFormSchema = KandangFormSchema;

export type KandangFormValues = Yup.InferType<typeof KandangFormSchema>;
