import {
  storageShopeeShopId, storageShopeeShopName,
  storageTiktokShopId, storageTiktokShopName,
  storageLazadaShopId, storageLazadaShopName,
} from '@/plugins/storage/items';

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

    this.storageId = storageId;
    this.storageName = storageName;
    this.isSync = isSync;

    this.load();
  }

  async load() {
    this.shopId = await this.storageId.getValue();
    this.shopName = await this.storageName.getValue();
  }

  setShopId(shopId) {
    if (this.isSync) {
      this.storageId.setValue(shopId);
    }
    this.shopId = shopId;
  }

  setShopName(shopName) {
    if (this.isSync) {
      this.storageName.setValue(shopName);
    }
    this.shopName = shopName;
  }
}

export const ShopeeShopIdentify = new ShopIdentify(storageShopeeShopId, storageShopeeShopName, false);

export const TiktokShopIdentify = new ShopIdentify(storageTiktokShopId, storageTiktokShopName, true);

export const LazadaShopIdentify = new ShopIdentify(storageLazadaShopId, storageLazadaShopName, true);
