/**
 * 用户信息接口
 */
import { request } from '../../utils/request'
import type { UserInfo } from '../../types/user'
import { encryptAES } from '../../utils/crypto'
import {getStoreIsKey} from '../../utils/storage'

/**
 * 获取用户信息
 */
export const getUserInfo = (userId: any): Promise<UserInfo> => {
    return request({
        url: '/system/user/'+userId,
        method: 'GET'
    })
}

/**
 * 更新用户信息
 */
export const updateUserInfo = (userInfo: UserInfo): Promise<boolean> => {
    return request<boolean>({
        url: '/api/user/info',
        method: 'PUT',
        data: userInfo as any as UTSJSONObject
    })
}

/**
 * 更新密码
 */
export const updatePassword = async (password: string, newPassword: string): Promise<any> => {
	let dataForm = {
		    newPassword: newPassword,
		    oldPassword: password
		};
		
	const isKey = getStoreIsKey();
	if(isKey == "1"){
		dataForm.newPassword = encryptAES(newPassword);
		dataForm.oldPassword = encryptAES(password);
	}
	return request({
        url: '/system/user/profile/updatePwd',
        method: 'PUT',
		header: {
		  isToken: false,
		  repeatSubmit: false
		},
        data: dataForm,
    })
}