import website from '@/config/website';
import request from '@/router/axios';

export const loginByUsername = (username, password, type, key, code, loginType, ticket) =>
    request({
      url: '/api/jobslink-auth/oauth/token',
      method: 'post',
      headers: {
        'Login-Type': loginType,
        'Captcha-Key': key,
        'Captcha-Code': code,
      },
      params: {
        username,
        password,
        grant_type: (website.captchaMode ? 'captcha' : 'password'),
        scope: 'all',
        type,
        ticket
      }
    });

export const refreshToken = (refresh_token, tenantId, authType) => request({
  url: '/api/jobslink-auth/oauth/token',
  method: 'post',
  headers: {
    'Tenant-Id': tenantId,
    'Login-Type': authType,
  },
  params: {
    tenantId,
    refresh_token,
    grant_type: 'refresh_token',
    scope: 'all',
  }
});

export const getButtons = () =>
    request({url: '/api/jobslink-api/system/menu/buttons', method: 'get'});

export const getCaptcha = () =>
    request({url: '/api/jobslink-auth/oauth/captcha', method: 'get'});

export const logout = () =>
    request({url: '/api/jobslink-auth/oauth/logout', method: 'get'});

export const getUserInfo = () =>
    request({url: '/api/jobslink-auth/oauth/user-info', method: 'get'});

export const sendLogs = (list) => request(
    {url: '/api/jobslink-auth/oauth/logout', method: 'post', data: list});

export const clearCache = () =>
    request({url: '/api/jobslink-auth/oauth/clear-cache', method: 'get'});
