import { getRequest } from '@/api/api'; // Vue.axios
// function getRequest(url, params) {
//   return Vue.axios({
//     method: 'get',
//     url: `${window.origin}${url}`,
//     data: {},
//     params: params,
//     headers: { 'content-type': 'application/x-www-form-urlencoded' } // "token": token
//   });
// }

export function getAccountStateInfo() {
  return getRequest('api-marketing/account-state-info', {
    requestProject: 'gic-clique'
  });
}

function getUserInfo() {
  return new Promise((resolve, reject) => {
    getRequest('/api-auth/get-login-user-info', {
      requestProject: 'gic-clique'
    })
      .then(res => {
        let resData = res.data;
        if (resData.errorCode == 0) {
          let result = resData.result || {};
          window.localStorage.setItem(
            'dmUserInfo',
            JSON.stringify({
              enterpriseId: result.enterpriseId,
              cliqueId: result.enterpriseDTO.cliqueId,
              clerkId: result.userId,
              damoUser: result.operationUserId,
              superAdmin: result.superAdmin
            })
          );
          resolve(result);
        } else {
          reject(resData);
        }
      })
      .catch(reject);
  });
}

export function getExpireExterprise(){
  return getRequest('/api-admin/get_expire_enterprise', {
    requestProject: 'gic-clique'
  })
}

export function getExpireData(params) {
  return new Promise((resolve, reject) => {
    getUserInfo()
      .then(() => {
        params = params || {};
        let dmUserInfo = JSON.parse(localStorage.getItem('dmUserInfo'));
        let serviceType = 11;
        return getRequest('/api-admin/enterprise_expirebar', {
          requestProject: 'gic-clique',
          serviceType: serviceType,
          cliqueId: dmUserInfo.cliqueId,
          clerkId: dmUserInfo.clerkId,
          isSuperAdmin: dmUserInfo.superAdmin,
          enterpriseId: dmUserInfo.enterpriseId,
          ...params
        })
          .then(resolve)
          .catch(reject);

        // resolve({
        //   params,
        //   data: {
        //     errorCode: 0,
        //     result: {
        //       expireStatus: 1,
        //       expireDayStr: '1111',
        //       allExpire: 1,
        //       clique: 1
        //     }
        //   }
        // });
      })
      .catch(reject);
  });
}
