import {
    request
} from '@/untils/AxiosUtils.js';
import {
    getStore
} from '@/untils/store.js'
import website from "@/config/website";

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

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

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'
});

export const mobileIsCms = () => request({
    url: '/api/jobslink-api/mobile/isCms',
    method: 'get'
})

export const noticeIsEnable = () => request({
    url: "/api/jobslink-api/desk/notice/isEnable",
    method: 'get',
});

export const setNoticeIsEnable = (state) => request({
    url: "/api/jobslink-api/desk/notice/isEnable/" + state,
    method: 'PUT',
});