import * as Yup from 'yup';

export const CustomerFormSchema = Yup.object({
  name: Yup.string().required('Nama 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(),
  }).required('PIC wajib diisi!'),

  type: Yup.object({
    value: Yup.string().required(),
    label: Yup.string().required(),
  }).required('Tipe wajib diisi!'),

  address: Yup.string().required('Alamat wajib diisi!'),

  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!'),

  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!'),
});

export const UpdateCustomerFormSchema = CustomerFormSchema;

export type CustomerFormValues = Yup.InferType<typeof CustomerFormSchema>;
