import PQueue from 'p-queue';
import { shopeeSaveLogPrintJob } from './shopee';
import { tiktokSaveLogPrintJob } from './tiktok';
import { lazadaSaveLogPrintJob } from './lazada';

const shopeePrintLogQueue = new PQueue({
  concurrency: 1,
});

const tiktokPrintLogQueue = new PQueue({
  concurrency: 1,
});

const lazadaPrintLogQueue = new PQueue({
  concurrency: 1,
});

/**
 * @param {string} printId
 * @param {string} shopId
 * @param {string} shopName
 * @returns {Promise<OrderPdfBucket>}
 */
export const pushShopeePrintLogJob = (printId, shopId, shopName) => {
  return shopeePrintLogQueue.add(async () => shopeeSaveLogPrintJob(printId, shopId, shopName));
};

/**
 * @param {string} pdfUrl
 * @param {string} shopId
 * @param {string} shopName
 * @returns {Promise<OrderPdfBucket>}
 */
export const pushTiktokPrintLogJob = (pdfUrl, shopId, shopName) => {
  return tiktokPrintLogQueue.add(async () => tiktokSaveLogPrintJob(pdfUrl, shopId, shopName));
};

/**
 * @param {string} pdfUrl
 * @param {string} shopId
 * @param {string} shopName
 * @returns {Promise<OrderPdfBucket>}
 */
export const pushLazadaPrintLogJob = (pdfUrl, shopId, shopName) => {
  return lazadaPrintLogQueue.add(async () => lazadaSaveLogPrintJob(pdfUrl, shopId, shopName));
};
