import * as Yup from 'yup';

export const SupplierFormSchema = Yup.object({
  name: Yup.string().required('Nama wajib diisi!'),
  alias: Yup.string()
    .matches(
      /^[A-Za-z0-9]+$/,
      'Alias hanya boleh berisi huruf dan angka tanpa spasi atau simbol!'
    )
    .max(5, 'Alias maksimal 5 karakter!')
    .required('Alias wajib diisi!'),
  pic: Yup.string().required('PIC wajib diisi!'),
  type: Yup.object({
    value: Yup.string().required(),
    label: Yup.string().required(),
  }).required('Tipe wajib diisi!'),
  category: Yup.object({
    value: Yup.string().required(),
    label: Yup.string().required(),
  }).required('Tipe wajib diisi!'),
  hatchery: Yup.string().optional(),
  phone: Yup.string()
    .matches(/^[0-9]+$/, 'Nomor telepon hanya boleh berisi angka!')
    .min(10, 'Nomor telepon minimal 10 digit!')
    .max(12, 'Nomor telepon maksimal 12 digit!')
    .required('Nomor telepon wajib diisi!'),
  email: Yup.string()
    .email('Format email tidak valid!')
    .required('Email wajib diisi!'),
  address: Yup.string().required('Alamat wajib diisi!'),
  npwp: Yup.string()
    .matches(/^[0-9]+$/, 'Nomor NPWP hanya boleh berisi angka!')
    .required('Nomor NPWP wajib diisi!'),
  bank_name: Yup.string()
    .min(3, 'Nama bank minimal 3 karakter!')
    .required('Nama bank wajib diisi!'),
  account_number: Yup.string()
    .matches(/^[0-9]+$/, 'Nomor rekening hanya boleh berisi angka!')
    .required('Nomor rekening wajib diisi!'),
  due_date: Yup.number()
    .min(1, 'Tanggal jatuh tempo wajib diisi!')
    .required('Tanggal jatuh tempo wajib diisi!'),
});

export const UpdateSupplierFormSchema = SupplierFormSchema;

export type SupplierFormValues = Yup.InferType<typeof SupplierFormSchema>;
