import { ModelApiLoader } from '@/api/model';
import joi, { joiString } from '@/validator/joi';

const schemaFlashSaleSave = joi.object({
  name: joi.string().required(),
  shopId: joiString.required(),
  shopName: joi.string().optional().default(''),
  flashSaleId: joiString.required(),
  urlOpen: joi.string().required(),
  urlClone: joi.string().required(),
});

const schemaFlashSaleScheduler = joi.object();

export const ShopeeFlashSaleSave = new ModelApiLoader('shopee_flashsale_save', schemaFlashSaleSave);

export const ShopeeFlashSaleScheduler = new ModelApiLoader('shopee_flashsale_scheduler', schemaFlashSaleScheduler);

export const loaderIndex = () => {
  return Promise.allSettled([
    ShopeeFlashSaleSave.createIndex({
      index: {
        fields: ['shopId', 'flashSaleId'],
      },
    }),
    ShopeeFlashSaleScheduler.createIndex({
      index: {
        fields: ['shopId'],
      },
    }),
  ]);
};
