import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { CaptchaResult, LoginData, LoginResult } from "./types";

/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): AxiosPromise<LoginResult> {
  // const formData = new FormData();
  // formData.append("userName", data.username);
  // formData.append("password", data.password);
  // formData.append("captchaKey", data.captchaKey || "");
  // formData.append("captchaCode", data.captchaCode || "");
  return request({
    url: "/api/auth/login",
    method: "post",
    data: data,
    // headers: {
    //   "Content-Type": "multipart/form-data",
    // },
  });
}

/**
 * 注销API
 */
export function logoutApi() {
  return request({
    url: "/api/auth/loginOut",
    method: "post",
  });
}

/**
 * 获取验证码
 */
export function getCaptchaApi(): AxiosPromise<CaptchaResult> {
  return request({
    url: "/api/v1/auth/captcha",
    method: "get",
  });
}

/**
 * 登录成功后获取用户字典
 */
export function getUserDicts(data: string[]): AxiosPromise {
  return request({
    url: "/api/v1/sys/dictData/queryByTypes",
    method: "post",
    data: data,
  });
}

export function getOrgListApi(): AxiosPromise<any[]> {
  return request({
    url: "/api/v1/sys/dept/orgList",
    method: "get",
  });
}
