import * as Yup from 'yup';
import { SalesOrderProductFormValues } from '@/components/pages/marketing/form/repeater/sales-order/SalesOrderProduct.schema';

type DeliveryOrderProductSchemaType = {
  id?: number | undefined;
  marketing_product_id: number | undefined; // Sales Order ID
  marketing_product?: SalesOrderProductFormValues | undefined | null;
  unit_price: string | number | undefined;
  total_weight: string | number | undefined;
  qty: string | number | undefined;
  avg_weight: string | number | undefined;
  total_price: string | number | undefined;
  vehicle_number: string | undefined;
  delivery_date: string | undefined | null;
  do_number?: string | undefined | null; // Uncertain
};

export const DeliveryOrderProductSchema: Yup.ObjectSchema<DeliveryOrderProductSchemaType> =
  Yup.object({
    id: Yup.number(),
    marketing_product_id: Yup.number()
      .min(1, 'Produk wajib diisi!')
      .required('Produk wajib diisi!'),
    marketing_product: Yup.object().nullable().optional(),
    unit_price: Yup.number()
      .min(1, 'Harga Satuan wajib diisi!')
      .required('Harga Satuan wajib diisi!'),
    total_weight: Yup.number()
      .min(0, 'Total Bobot wajib diisi!')
      .required('Total Bobot wajib diisi!'),
    qty: Yup.number()
      .min(1, 'Kuantitas wajib diisi!')
      .required('Kuantitas wajib diisi!'),
    avg_weight: Yup.number()
      .min(0, 'Avg. Bobot wajib diisi!')
      .required('Avg. Bobot wajib diisi!'),
    total_price: Yup.number()
      .min(1, 'Total Penjualan wajib diisi!')
      .required('Total Penjualan wajib diisi!'),
    vehicle_number: Yup.string().required('Nomor Kendaraan wajib diisi!'),
    delivery_date: Yup.string().required('Tanggal Pengiriman wajib diisi!'),
    do_number: Yup.string().nullable().optional(),
  });

export type DeliveryOrderProductFormValues = Yup.InferType<
  typeof DeliveryOrderProductSchema
>;
