import request from "@/utils/request";
import { CaptchaResult, LoginData, LoginResult } from "./model";

class AuthAPI {
  /**
   * 登录API
   *
   * @param data {LoginData}
   * @returns
   */
  static login(data: LoginData) {    
    /*
    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<any, LoginResult>({
      url: "/api/v1/auth/login",
      method: "post",
      data: formData,
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });*/
    return new Promise((resolve,reject)=>{
      if(data.username!='admin' || data.password!='123456'){
        reject("用户名或密码错误");
      }else{
        resolve( {
              "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImRlcHRJZCI6MSwiZGF0YVNjb3BlIjoxLCJleHAiOjE3MTYyMjY0OTksInVzZXJJZCI6MiwiaWF0IjoxNzE2MjE5Mjk5LCJhdXRob3JpdGllcyI6WyJST0xFX0FETUlOIl0sImp0aSI6IjVmMWIwNTExNmZjZDQxZmE5YTVlNjU4ZjQ5YmRmNmEyIn0.BBCWh3-bffEtgT0zhxSQ0ncithh9iIGDtbg1DPN0TvA",
              "tokenType": "Bearer",
              "refreshToken": null,
              "expires": null
          });
      }
    });
  }

  /**
   * 注销API
   */
  static logout() {
    return new Promise(r=>{
      r({});
    });
    /*
    return request({
      url: "/api/v1/auth/logout",
      method: "delete",
    });
    */
  }

  /**
   * 获取验证码
   */
  static getCaptcha() {
    return request<any, CaptchaResult>({
      url: "/api/v1/auth/captcha",
      method: "get",
    });
  }
}

export default AuthAPI;
