import request from '@/utils/request';
import store from '@/store';
// 获取cookie
export const getUserCookie = () => {
  return store.getters['user/token'];
};
// 登录
export const UserLogin = (data: any) => {
  return request.post('/api/users/login', {
    ...data,
  });
};

// 获取后台配置
export const getAdminConfig = () => {
  let token = getUserCookie();
  return request.get('/api/users/config', {
    headers: {
      authorization: `Bearer ${token}`,
    },
  });
};

// 获取阿里云上传策略
export const getConfigPolicy = (data: any) => {
  let token = getUserCookie();
  return request.get('/api/users/config/policy', {
    params: data,
    headers: {
      authorization: `Bearer ${token}`,
    },
  });
};

// 退出登录
export const useLogout = () => {
  return request.post(
    '/api/users/logout',
    {},
    {
      headers: {
        authorization: `Bearer ${getUserCookie()}`,
      },
    }
  );
};

// 提交任务
export const useSubmitTask = (data: any) => {
  return request.post(
    '/api/users/submit',
    { ...data },
    {
      headers: {
        authorization: `Bearer ${getUserCookie()}`,
      },
    }
  );
};

// 轮询检测任务
export const IntervalCheckTask = (data: any) => {
  return request.get('/api/users/task/callback', {
    params: data,
    headers: {
      authorization: `Bearer ${getUserCookie()}`,
    },
  });
};

// 提交切割图片任务
export const SubmitSplitImgTask = (data: any) => {
  return request.post(
    '/api/users/split',
    { ...data },
    {
      headers: {
        authorization: `Bearer ${getUserCookie()}`,
      },
    }
  );
};

// 轮询获取图片切割任务状态
export const get_split_img_status = (data: any) => {
  return request.get('/api/users/split/status', {
    params: data,
    headers: {
      authorization: `Bearer ${getUserCookie()}`,
    },
  });
};
