import { shopeeSetting } from '@/plugins/setting';
import { imageUrl } from '@/adapter/shopee/render/index';

export const mutations = {
  /**
   *
   * @param {StoreShopeeShop} state
   * @param {ShopeeShopProfile} shopInfo
   */
  SET_SHOPEE_SELLER_INFO(state, shopInfo) {
    const shopId = shopInfo.shopid || shopInfo.shop_id;
    const username = shopInfo.username || shopInfo.user_id;

    state.id = shopId;
    state.name = username;
    state.image = imageUrl(shopInfo.portrait);
    state.shopInfo = shopInfo;
    shopeeSetting.shopeeShopId.set(state.id);
    shopeeSetting.shopeeShopName.set(state.name);
    shopeeSetting.shopeeShopImage.set(state.image);
    state.isInited = true;
  },
  SET_SHOPEE_SELLER_SHOP_ID(state, shopId) {
    state.id = shopId;
    shopeeSetting.shopeeShopId.set(shopId);
  },
  SET_SHOPEE_SELLER_SHOP_NAME(state, shopName) {
    state.name = shopName;
    shopeeSetting.shopeeShopName.set(shopName);
  },
  /**
   *
   * @param {StoreShopeeShop} state
   * @param {object} shopSync
   */
  SET_SHOPEE_SELLER_SYNC(state, shopSync) {
    state.shopSync = shopSync;
    state.ref = shopSync._id;
    shopeeSetting.shopeeShopRef.set(state.ref);
  },
  /**
   *
   * @param {StoreShopeeShop} state
   */
  SET_SHOPEE_SELLER_UNSYNC(state) {
    state.shopSync = {};
    state.ref = '';
    shopeeSetting.shopeeShopRef.set('');
  },
  /**
   *
   * @param {StoreShopeeShop} state
   * @param {string} SPC_F
   */
  SET_SHOPEE_SELLER_SPC_F(state, SPC_F) {
    state.spcf = SPC_F;
    shopeeSetting.shopeeShopSpcf.set(SPC_F);
  },
  /**
   *
   * @param {StoreShopeeShop} state
   * @param {string} SPC_CDS
   */
  SET_SHOPEE_SELLER_SPC_CDS(state, SPC_CDS) {
    state.spccds = SPC_CDS;
    shopeeSetting.shopeeShopSpcCds.set(SPC_CDS);
  },
  SET_SHOPEE_SELLER_LOGISTIC(state, value) {
    state.shopLogistic.selected = value;
  },
  SET_SHOPEE_SELLER_WAREHOUSE(state, value) {
    state.shopWarehouse.selected = value;
  },
};
