import { request } from '../request';

/**
 * 获取验证码
 * @param phone - 手机号
 * @returns - 返回boolean值表示是否发送成功
 */
export function fetchSmsCode(phone: string) {
  return request.post<boolean>('/getSmsCode', { phone });
}

// 参数接口
export interface AdminLoginParams {
  username: string;
  passwd: string;
  captchaVerification: string;
}

// 响应接口
export interface AdminLoginRes {
  status: boolean;
  msg: string;
  data: Record<string, unknown>;
}

/**
 * 登录
 * @param userName - 用户名
 * @param password - 密码
 * @param captchaVerification - 验证码
 */
export function fetchLogin(params: AdminLoginParams) {
  const res = request.post('/login/adminLogin', params);
  return res;
}

/**
 * 登录
 * @param userName - 用户名
 * @param password - 密码
 * @param captchaVerification - 验证码
 */
export function fetchStudentLogin(params: AdminLoginParams) {
  const res = request.post('/login/studentLogin', params);
  return res;
}

/** 获取用户信息 */
export function fetchUserInfo() {
  const res = request.get('/login/getUserInfo');
  return res;
}

/**
 * 刷新token
 * @param refreshToken
 */
export function fetchUpdateToken(refreshToken: string) {
  return request.post<ApiAuth.Token>('/login/refreshToken', refreshToken);
}
