import '@/types/Store/Shopee/Shopee';
import { getShortLink } from '@/api/shopee/affiliate';
import { shopeeSetting } from '@/plugins/setting';

/** @type {VuexStoreModule} */
export const affiliateStore = {
  state() {
    return {
      token: shopeeSetting.shopeeAffToken.get(),
      id: shopeeSetting.shopeeAffId.get(),
      subId: shopeeSetting.shopeeAffSubId.get(),
      content: shopeeSetting.shopeeAffContent.get(),
    };
  },
  mutations: {
    SET_SHOPEE_AFFILIATE_CONFIG(state, { id, token }) {
      state.token = token;
      state.id = id;
      shopeeSetting.shopeeAffToken.set(token);
      shopeeSetting.shopeeAffId.set(id);
    },
    SET_SHOPEE_AFFILIATE_SUBID(state, data) {
      state.subId = data;
      shopeeSetting.shopeeAffSubId.set(data);
    },
    SET_SHOPEE_AFFILIATE_CONTENT(state, content) {
      state.content = content;
      shopeeSetting.shopeeAffContent.set(content);
    },
  },
  getters: {
    getAffiliateShopee(state) {
      return state;
    },
  },
  actions: {
    ShopeeAffiliateConfig({ commit }, data) {
      commit('SET_SHOPEE_AFFILIATE_CONFIG', data);
    },
    ShopeeAffiliateSubId({ commit }, data) {
      commit('SET_SHOPEE_AFFILIATE_SUBID', data);
    },
    ShopeedAffiliateContent({ commit }, content) {
      commit('SET_SHOPEE_AFFILIATE_CONTENT', content);
    },
    ShopeeGetShortLink(_, url) {
      return getShortLink(url);
    },
  },
};
