import { ShopeeOrderPdfPrintJob } from '@/models/orderPdf';
import { getShopeePrintPdf } from '@/api/shopee/seller/order/print';
import { saveLogPrintJob } from './service';

const PLATFORM = 'shopee';

const REGEX_EXTRACT_ID = {
  trackingCodes: /\bSPX[A-Z0-9]{5,}\b/g,
  orderCodes: /\b\d{8}[A-Z0-9]{6}\b/g,
};

/**
 * @param {string} printId
 * @param {string} shopId
 * @param {string} shopName
 * @returns {Promise<OrderPdfBucket>}
 */
export const shopeeSaveLogPrintJob = async (printId, shopId, shopName) => {
  return saveLogPrintJob(
    printId,
    shopId,
    shopName,
    PLATFORM,
    ShopeeOrderPdfPrintJob,
    () => getShopeePrintPdf(printId),
    REGEX_EXTRACT_ID,
  );
};
