import { request } from "@/utils/service"
import * as AxiosType from "axios"
import * as Requests from "@/api/types/requests"
import {
  IAccountInfo,
  IChangeUserStatus,
  IDelUserResponseData,
  IExChangeAccountRequestsData,
  IExChangeUserResponseData,
  IGetAllUserResponseData
} from "@/api/users/types/users"
import { AxiosResponseData } from "@/api/types/requests"
import { getAuthByRoleId } from "@/api/register/types/register"

export function getAllUsersApi(page: number) {
  return request<AxiosType.AxiosResponse<Requests.IResponseData<IGetAllUserResponseData>>>({
    url: "/account/getUser",
    method: "get",
    params: {
      page: page,
      num: 10
    },
    withCredentials: true
  })
}
export function delUserApi(userId: number) {
  return request<AxiosType.AxiosResponse<Requests.IResponseData<IDelUserResponseData>>>({
    url: "/account/delUser",
    method: "get",
    params: {
      id: userId
    },
    withCredentials: true
  })
}
export function exChangeUserDataApi(newUser: IExChangeAccountRequestsData) {
  newUser.auth = getAuthByRoleId(newUser.roleId)
  return request<AxiosType.AxiosResponse<Requests.IResponseData<IExChangeUserResponseData>>>({
    url: "/account/changeAccount",
    method: "post",
    data: newUser,
    withCredentials: true
  })
}
export function changeUserStatusApi(userid: number, newStatus: boolean) {
  return request<AxiosType.AxiosResponse<Requests.IResponseData<IChangeUserStatus>>>({
    url: "/account/changeStatus",
    method: "get",
    params: {
      userId: userid,
      status: newStatus
    },
    withCredentials: true
  })
}
export function getUserInfoApi() {
  return request<AxiosResponseData<IAccountInfo>>({
    url: "/account/getUserInfo",
    method: "get",
    withCredentials: true
  })
}
export function getRemainderTime(userId: number) {
  return request<AxiosResponseData<{ remainderTime: number }>>({
    url: "/verify/getRemainderTime",
    method: "get",
    params: {
      id: userId
    },
    withCredentials: true
  })
}
export function verify(userId: number, name: string, phone: string) {
  return request<AxiosResponseData<{ remainderTime: number }>>({
    url: "/verify/verify",
    method: "get",
    params: {
      id: userId,
      name: name,
      phone: phone
    },
    withCredentials: true
  })
}
export function getVerifyMessage(userId: number) {
  return request<AxiosResponseData<{ phone: string; name: string; storeId: number }[]>>({
    url: "/verify/getVerifyMessage",
    method: "get",
    params: {
      createId: userId
    },
    withCredentials: true
  })
}
export function confirmVerify(createdId: number, storeId: number, status: boolean) {
  return request<AxiosResponseData<string>>({
    url: "/verify/confirmVerify",
    method: "get",
    params: {
      createId: createdId,
      storeId: storeId,
      status: status
    },
    withCredentials: true
  })
}
