/**
 * 登录接口
 */
import { request } from '../../utils/request'
import { encryptAES } from '../../utils/crypto'
import {getStoreIsKey} from '../../utils/storage'

/**
 * 账号密码登录
 * @returns 返回整个响应对象 { status, msg, success, data }
 */
export const loginByAccount = async (username: string, password: string): Promise<any> => {
    let dataForm = {
    		username: username,
    	    password: password,
			deviceCode: 'app',
    	};
	
   /* const isKey = getStoreIsKey();
    if(isKey == "1"){
    	dataForm.username = encryptAES(username);
    	dataForm.password = encryptAES(password);
    } */
	
	return request({
        url: '/login',
        method: 'POST',
		header: {
		  isToken: false,
		  repeatSubmit: false
		},
        data: dataForm,
    })
}


/**
 * SSO账号登录
 * @returns 返回整个响应对象 { status, msg, success, data }
 */
export const loginSSO = async (apptoken: string): Promise<any> => {	
	return request({
        url: `/ice/sso/login`,
        method: 'POST',
		header: {
		  isToken: false,
		  repeatSubmit: false
		},
		data:  {apptoken: apptoken}
    })
}

export const getUserInfo = ():Promise<any> =>{
	return request({
		url: '/getInfo',
		method: 'GET'
	})
}

export const resetPassword = async (username: string, password: string, newPassword: string): Promise<any> => {
	let dataForm = {
			username: username,
		    newPassword: newPassword,
		    password: password
		};

	return request({
        url: '/initPassword',
        method: 'PUT',
		header: {
		  isToken: false,
		  repeatSubmit: false
		},
        data: dataForm,
    })
}

export const getIsKey = ():Promise<any> =>{
	return request({
		url: '/crypto/isKey',
		method: 'GET'
	})
}