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

export const InventoryAdjustmentFormSchema = Yup.object({
  product_category: Yup.mixed<OptionType>()
    .nullable()
    .test(
      'is-valid-option',
      'Kategori Produk wajib diisi!',
      (value) => value !== null && value !== undefined
    ),

  product_category_id: Yup.number().nullable(),

  product: Yup.mixed<OptionType>()
    .nullable()
    .test(
      'is-valid-option',
      'Produk wajib diisi!',
      (value) => value !== null && value !== undefined
    ),

  product_id: Yup.number()
    .nullable()
    .required('Produk wajib diisi!')
    .min(1, 'Produk wajib diisi!'),

  warehouse: Yup.mixed<OptionType>()
    .nullable()
    .test(
      'is-valid-option',
      'Warehouse wajib diisi!',
      (value) => value !== null && value !== undefined
    ),

  warehouse_id: Yup.number()
    .nullable()
    .required('Warehouse wajib diisi!')
    .min(1, 'Warehouse wajib diisi!'),

  transaction_type: Yup.string()
    .oneOf(['increase', 'decrease'], 'Tipe transaksi tidak valid')
    .nullable()
    .required('Tipe transaksi wajib diisi'),

  quantity: Yup.number()
    .typeError('Kuantitas harus berupa angka')
    .min(1, 'Minimal kuantitas adalah 1')
    .required('Kuantitas wajib diisi'),

  note: Yup.string().required('Catatan wajib diisi!'),
});

export type InventoryAdjustmentFormValues = Yup.InferType<
  typeof InventoryAdjustmentFormSchema
>;
