/*
 * @Author: xiejiang
 * @Date: 2024-11-05 10:14:56
 * @LastEditors: xiejiang
 * @LastEditTime: 2024-12-03 14:15:47
 * @Description:
 * Copyright（c）2024 by 好老师教育科技有限公司 All right Reserved.
 */
import http from '@/api'
import { UserInfo } from '@/stores/interface'
import { ReqLoginMsg, Captcha } from '@/api/interface/login'

const api = {
  loginBySmsCode: '/platform/login/smsLogin', // 手机号、短信验证码登录
  userInfo: '/platform/login/currentLoginInfo', // 获取当前登录用户信息
  getSmsCode: '/platform/login/getSmsCode', //获取短信验证码
  getCheckSliderCode: '/platform/login/checkSliderCode', // 校验滑动验证码
  getSliderCaptcha: '/platform/login/getSliderCaptcha' // 生成滑动验证码拼图
}

/**
 * 获取登录用户信息
 * docs: http://api.seevin.com/project/172/interface/api/20248
 */
export const getUserInfo = (loading: string | boolean = '用户信息加载中...') => {
  return http.get<UserInfo>(api.userInfo, {}, { loading: loading })
}
// 用户退出登录
export const logoutApi = () => {
  return http.post(`/logout`)
}

/**
 * 手机号、短信验证码登录
 * docs: http://api.seevin.com/project/172/interface/api/20240
 */
export const LoginBySmsCode = (data: ReqLoginMsg) => {
  return http.post<UserInfo>(api.loginBySmsCode, data, { loading: '登录中...', noToken: true })
}

// 获取短信验证码
export const getSmsCode = (params: { telephone: string }) => {
  return http.get(api.getSmsCode, params, { noToken: true })
}

/**
 * @description 校验滑动验证码
 * @author 汪洋
 * @docs http://api.seevin.com/project/669/interface/api/33120
 * @param nonceStr 图形验证唯一编码
 * @param blockY 阻塞块的纵轴坐标
 */
export const getCheckSliderCode = (params: Captcha) => {
  return http.get(api.getCheckSliderCode, params, { noToken: true })
}

/**
 * @description 生成滑动验证码拼图
 * @author 汪洋
 * @docs http://api.seevin.com/project/669/interface/api/33122
 * @param nonceStr 随机字符串
 * @param value 验证值
 * @param canvasSrc 生成的画布的base64
 * @param canvasWidth 画布宽度
 * @param canvasHeight 画布高度
 * @param blockSrc 生成的阻塞块的base64
 * @param blockWidth 阻塞块宽度
 * @param blockHeight 阻塞块高度
 * @param blockRadius 阻塞块凸凹半径
 * @param blockX 阻塞块的横轴坐标
 * @param blockY 阻塞块的纵轴坐标
 * @param place 图片获取位置
 */
export const getSliderCaptcha = () => {
  return http.get<Captcha>(api.getSliderCaptcha, { noToken: true })
}
