import flyio from "../flyio";
import { ApiCaptchaResponse, ApiResponse, DictItem, ConfigItem, System, ApiResponseList } from "@/types";
import { SmsRequestDTO } from "@/types/user";

/**
 * 获取配置属性
 * @returns 
 */
export function getConfig() {
  return flyio.get('/front/comm/config') as Promise<ApiResponse<ConfigItem[]>>;
}

/**
 * 获取字典数据
 * @param dictTypes 字典类型列表，逗号分隔
 * @returns 
 */
export function getDictData(dictTypes: string) {
  return flyio.get(`/front/comm/dict/${dictTypes}`) as Promise<ApiResponse<Record<string, DictItem[]>>>;
}

/**
 * 发送短信验证码, 发送验证码(不验重,验证码,不登陆), 适用于账号登录
 * @param params 包含手机号等参数的对象
 * @returns 
 */
export function sendSmsNoValidationNoToken(params: SmsRequestDTO) {
  // 使用POST方法，参数通过URL查询字符串传递
  return flyio.post('/front/comm/sendSmsNoValidationNoToken', null, { params }) as Promise<ApiResponse<any>>;
}

/**
 * 发送短信验证码, 发送验证码(验重,验证码,不登陆), 适用于账号注册
 * @param params 包含手机号等参数的对象
 * @returns 
 */
export function sendSmsNoToken(params: SmsRequestDTO, showToast = true) {
  return flyio.post('/front/comm/sendSmsNoToken', null, { params }, {
    showToast
  }) as Promise<ApiResponse<any>>;
}

/**
 * 发送短信验证码, 发送验证码(不验重,无验证码,需登陆), 适用于登录后的校验
 * @param params 包含手机号等参数的对象
 * @returns 
 */
export function sendSms(params: SmsRequestDTO) {
  return flyio.post('/front/comm/sendSms', null, { params }) as Promise<ApiResponse<any>>;
}

/**
 * 获取省份列表
 * @returns 
 */
export function getProvinces() {
  // return flyio.get('/front/user/provinces') as Promise<ApiResponse<DictItem[]>>;
  const params = {
    columns: 'id,full_name,parent_id,has_children'
  }
  return flyio.get('/system/area/list/tree', { params }) as Promise<ApiResponseList<System.ProvinceItem>>;
}

/**
 * 获取考生类别
 * @returns 
 */
export function getExamTypes(location: string) {
  return flyio.get('/front/user/examTypes', { location }) as Promise<ApiResponse<DictItem[]>>;
}

/**
 * 获取专业列表
 * @returns 
 */
export function getExamMajors(location: string, examType: string) {
  return flyio.get('/front/user/examMajors', { location, examType }) as Promise<ApiResponse<DictItem[]>>;
}

/**
 * 获取毕业年份列表
 * @returns 
 */
export function getGraduateYears(location: string, examType: string) {
  return flyio.get('/front/user/graduateYears', { location, examType }) as Promise<ApiResponse<DictItem[]>>;
}

/**
 * 获取验证码图片
 * @returns 
 */
export function getCaptchaImage() {
  return flyio.get('/captchaImage') as Promise<ApiCaptchaResponse>;
}


/**
 * 验证短信验证码
 * @param params 包含手机号等参数的对象
 * @returns 
 */
export function validateSms(params: SmsRequestDTO) {
  return flyio.post('/front/comm/validateSms', null, { params }) as Promise<ApiResponse<any>>;
}
