import request from "@/utils/request";
import { MenuVO } from "./menu";
import { UserForm } from "./user";

const AUTH_BASE_URL = "/api";

class AuthAPI {
  /** 登录 接口*/
  static login(data: LoginData) {
    return request<any, LoginResult>({
      url: `/api/admin/login`,
      method: "post",
      data: { userName: data.phone, password: data.code },
    });
  }

  /** 注销 接口*/
  static logout() {
    return request({
      url: `/api/admin/logOut`,
      method: "POST",
    });
  }

  /** 获取验证码 接口*/
  static getCaptcha(data: { phone: string }) {
    return request<any, CaptchaResult>({
      url: `/api/user/sendMsg`,
      method: "get",
      params: data,
    });
  }

  // 查询手机号绑定货场
  static getCommonDbPhone(data: { phone: string }) {
    return request<any, DbPhoneResult[]>({
      url: `/api/db/getCommonDbPhone`,
      method: "get",
      params: data,
    });
  }
}

export default AuthAPI;

/** 登录请求参数 */
export interface LoginData {
  /** 用户名 */
  phone: string;
  /** 密码 */
  code: string;
}

/** 登录响应 */
export interface LoginResult {
  /** 访问token */
  token?: string;
  menusList?: MenuVO[];
  roleList?: any;
  userId?: string;
  userInfo?: UserForm;
  userName?: string;
}

/** 验证码响应 */
export interface CaptchaResult {
  /** 验证码缓存key */
  captchaKey: string;
  /** 验证码图片Base64字符串 */
  captchaBase64: string;
}

// 查询手机号绑定货场相应
export interface DbPhoneResult {
  id: number;
  mechanismName: string;
  phone: string;
  mechanismCode: string;
  desc: string;
  isDefault: string;
}
