import { eLevel, eNewRoleRelatedToBackEnd, eRole } from "@/types/roleType";
import baseAxios from "../index";
import { eCheckPhoneStatus } from "./types";

const prefix = "/user";

/* 成功修改后会退出登录 */
export function userChangePhone(data: {
  newPhone: string;
  newVerifyCode: string;
  phone: string;
  verifyCode: string;
}) {
  return baseAxios({
    method: "post",
    url: prefix + "/change/phone",
    data,
  });
}

/* 成功修改后会退出登录 */
export function userChangePwd(data: {
  new_pwd: string;
  phone: string;
  verify_code: string;
}) {
  return baseAxios({
    method: "post",
    url: "/change/pwd",
    data,
  });
}

export function userCheckPhone(phone: string) {
  return baseAxios<eCheckPhoneStatus>({
    url: prefix + "/check/phone",
    method: "get",
    params: {
      phone,
    },
  });
}

export function userCreate(data: {
  phone: string;
  staffID?: string;
  verifyCode: string;
}) {
  return baseAxios({
    url: prefix + "/create",
    method: "POST",
    data,
  });
}

/* 用户可通过验证码或密码登录 */
export function userLogin(data: {
  is_admin: boolean;
  phone: string;
  use_pwd: boolean;
  pwd?: string;
  verify_code?: string;
}) {
  return baseAxios<{
    accessToken: string;
    level: eLevel;
    phone: string;
    role: eNewRoleRelatedToBackEnd;
  }>({
    url: "/login",
    method: "POST",
    data,
  });
}

export function userLogout() {
  return baseAxios({
    url: "/logout",
    method: "GET",
  });
}

export function userRegister(data: { phone: string; verify_code: string }) {
  return baseAxios<{
    accessToken: string;
    phone: string;
    role: eNewRoleRelatedToBackEnd;
  }>({
    url: "/user/register",
    method: "post",
    data,
  });
}

// function padding(all: number): any;
// function padding(topAndBottom: number, leftAndRight: number): any;
// function padding(top: number, right: number, bottom: number, left: number): any;
// // Actual implementation that is a true representation of all the cases the function body needs to handle
// function padding(a: number, b?: number, c?: number, d?: number) {
//   if (b === undefined && c === undefined && d === undefined) {
//     b = c = d = a;
//   } else if (c === undefined && d === undefined) {
//     c = a;
//     d = b;
//   }
//   return {
//     top: a,
//     right: b,
//     bottom: c,
//     left: d
//   };
// }

// padding(1, 2, 3, 4)
