import * as Yup from 'yup';

type ChickinRequestSchemaType = {
  chick_in_date: string;
  note?: string | undefined | null;
  product_warehouse_id: number;
};

type ChickinSchemaType = {
  project_flock_kandang_id: number;
  chickin_requests: ChickinRequestSchemaType[];
};

export const ChickinRequestSchema: Yup.ObjectSchema<ChickinRequestSchemaType> =
  Yup.object({
    chick_in_date: Yup.string().nullable().required('Tanggal wajib diisi!'),
    note: Yup.string().nullable(),
    product_warehouse_id: Yup.number()
      .min(1, 'Produk wajib diisi!')
      .required('Produk wajib diisi!'),
  });

export const ChickinSchema: Yup.ObjectSchema<ChickinSchemaType> = Yup.object({
  project_flock_kandang_id: Yup.number()
    .min(1, 'Project Flock Kandang wajib diisi!')
    .required('Project Flock Kandang wajib diisi!'),
  chickin_requests: Yup.array()
    .of(ChickinRequestSchema)
    .min(1, 'Minimal harus ada 1 produk!')
    .required('Produk wajib diisi!'),
});

export type ChickinRequestFormValues = Yup.InferType<
  typeof ChickinRequestSchema
>;

export type ChickinFormValues = Yup.InferType<typeof ChickinSchema>;
