import {
  IAddFlagResponse,
  IAddOrderResponse,
  IChangeOrderResponse,
  IChangeStatusResponse,
  IGetOrderUserInfoResponseData,
  IOrder,
  IRemoveOrderResponse,
  ISearchType
} from "@/api/order/types/order"
import { request } from "@/utils/service"
import * as AxiosType from "axios"
import { IPageResponseData, IResponseData } from "@/api/types/requests"

export function addOrderApi(order: IOrder) {
  return request<AxiosType.AxiosResponse<IResponseData<IAddOrderResponse>>>({
    url: "/order/addOrder",
    method: "POST",
    data: order,
    withCredentials: true
  })
}
export function getAllOrderApi(pageNum: number) {
  return request<AxiosType.AxiosResponse<IResponseData<IPageResponseData<IOrder>>>>({
    url: "/order/getOrder",
    method: "GET",
    params: {
      page: pageNum,
      num: 10
    },
    withCredentials: true
  })
}

export function getOrderUserInfoApi(content: string) {
  return request<AxiosType.AxiosResponse<IResponseData<IGetOrderUserInfoResponseData>>>({
    url: "/order/getOrderUserInfo",
    method: "GET",
    params: {
      content: content
    },
    withCredentials: true
  })
}
export function addFlagApi(order: IOrder) {
  return request<AxiosType.AxiosResponse<IResponseData<IAddFlagResponse>>>({
    url: "/order/addOrderFlag",
    method: "GET",
    params: {
      orderId: order.id,
      flagId: order.flag,
      flagRemark: order.flagRemark
    },
    withCredentials: true
  })
}
export function changeOrderApi(order: IOrder) {
  return request<AxiosType.AxiosResponse<IResponseData<IChangeOrderResponse>>>({
    url: "/order/changeOrder",
    method: "POST",
    data: order,
    withCredentials: true
  })
}
export function removeOrderApi(orderId: number) {
  return request<AxiosType.AxiosResponse<IResponseData<IRemoveOrderResponse>>>({
    url: "/order/delOrder",
    method: "GET",
    params: {
      orderId: orderId
    },
    withCredentials: true
  })
}
export function changeStatusApi(order: IOrder) {
  return request<AxiosType.AxiosResponse<IResponseData<IChangeStatusResponse>>>({
    url: "/order/confirm",
    method: "GET",
    params: {
      orderStatus: order.orderStatus,
      orderId: order.id
    },
    withCredentials: true
  })
}
export function searchOrderApi(type: ISearchType, content: string, page: number) {
  return request<AxiosType.AxiosResponse<IResponseData<IPageResponseData<IOrder>>>>({
    url: "/order/searchUserOrder",
    method: "GET",
    params: {
      searchType: type,
      searchContent: content,
      batch: content.indexOf(",") != -1,
      page: page,
      num: 10
    },
    withCredentials: true
  })
}
