import { apiApp } from '@/api/autoshopee/api';

// Flashsale Scheduler

/**
 * @param {string} shopId
 * @returns {Promise<FlashSaleListScheduler[]>}
 */
export const apiFlashsaleSchedulerList = async (shopId) => {
  try {
    const result = await apiApp.get('/extension/shopee/flashsale/scheduler/list', {
      params: {
        shopId,
      },
    });

    return result.data || [];
  } catch (error) {
    return [];
  }
};

/**
 * @param {string} shopId
 * @returns {Promise<FlashSaleListScheduler[]>}
 */
export const apiFlashsaleSchedulerSlot = async (shopId) => {
  try {
    const result = await apiApp.get('/extension/shopee/flashsale/scheduler/slot', {
      params: {
        shopId,
      },
    });

    return result.data || [];
  } catch (error) {
    return [];
  }
};

/**
 * @param {string} refId
 * @returns {Promise<FlashSaleListScheduler>}
 */
export const apiFlashsaleSchedulerGetId = async (refId) => {
  try {
    const result = await apiApp.get(`/extension/shopee/flashsale/scheduler/get/${refId}`);
    return result.data;
  } catch (error) {
    return null;
  }
};

/**
 * @param {FlashSaleListScheduler} payload
 * @returns {Promise<FlashSaleListScheduler>}
 */
export const apiFlashsaleSchedulerCreate = async (payload) => {
  try {
    const result = await apiApp.post('/extension/shopee/flashsale/scheduler/create', payload);
    return result.data;
  } catch (error) {
    return null;
  }
};

/**
 * @param {string} removeId
 * @returns {Promise<void>}
 */
export const apiFlashsaleSchedulerRemove = async (removeId) => {
  return apiApp.post(`/extension/shopee/flashsale/scheduler/remove/${removeId}`);
};

/**
 * @param {string} setId
 * @param {string} flashsaleId
 * @returns {Promise<void>}
 */
export const apiFlashsaleSchedulerSetId = async (setId, flashsaleId) => {
  return apiApp.post(`/extension/shopee/flashsale/scheduler/set/${setId}`, { flashsaleId });
};

// Flashsale Campagin
/**
 * @param {string} shopId
 * @returns {Promise<FlashSaleCampaignScheduler[]>}
 */
export const apiFlashsaleCampaignList = async (shopId) => {
  try {
    const result = await apiApp.get('/extension/shopee/flashsale/campaign/list', {
      params: {
        shopId,
      },
    });

    return result.data || [];
  } catch (error) {
    return [];
  }
};

/**
 * @param {FlashSaleCampaignScheduler} payload
 * @returns {Promise<FlashSaleCampaignScheduler>}
 */
export const apiFlashsaleCampaignCreate = async (payload) => {
  try {
    const result = await apiApp.post('/extension/shopee/flashsale/campaign/create', payload);
    return result.data;
  } catch (error) {
    return null;
  }
};

/**
 * @param {string} updateId
 * @param {FlashSaleCampaignScheduler} payload
 */
export const apiFlashsaleCampaignUpdate = async (updateId, payload) => {
  return apiApp.post(`/extension/shopee/flashsale/campaign/update/${updateId}`, payload);
};

/**
 * @param {string} removeId
 * @returns {Promise}
 */
export const apiFlashsaleCampaignRemove = async (removeId) => {
  return apiApp.post(`/extension/shopee/flashsale/campaign/remove/${removeId}`);
};

/**
 * @param {string} campaignId
 * @returns {Promise<FlashSaleCampaignScheduler>}
 */
export const apiFlashsaleCampaignGetId = async (campaignId) => {
  try {
    const result = await apiApp.get(`/extension/shopee/flashsale/campaign/get/${campaignId}`);
    return result.data;
  } catch (error) {
    return null;
  }
};
