import { tiktokSetting, lazadaSetting, shopeeSetting } from '@/plugins/setting';

class ShopIdentify {
  constructor(shopIdSetting, shopNameSetting, isSync = false) {
    this.shopId = '';
    this.shopName = '';

    this.shopIdSetting = shopIdSetting;
    this.shopNameSetting = shopNameSetting;
    this.isSync = isSync;

    this.load();
  }

  async load() {
    this.shopId = await this.shopIdSetting.getSync();
    this.shopName = await this.shopNameSetting.getSync();
  }

  setShopId(shopId) {
    if (this.isSync) {
      this.shopIdSetting.set(shopId);
    }
    this.shopId = shopId;
  }

  setShopName(shopName) {
    if (this.isSync) {
      this.shopNameSetting.set(shopName);
    }
    this.shopName = shopName;
  }
}

export const ShopeeShopIdentify = new ShopIdentify(shopeeSetting.shopeeShopId, shopeeSetting.shopeeShopName, false);

export const TiktokShopIdentify = new ShopIdentify(tiktokSetting.tiktokShopId, tiktokSetting.tiktokShopName, true);

export const LazadaShopIdentify = new ShopIdentify(lazadaSetting.lazadaShopId, lazadaSetting.lazadaShopName, true);
