import {
  IAddFlagResponse,
  IAddOrderResponse,
  IChangeOrderResponse,
  IGetOrderUserInfoResponseData,
  IOrder,
  IRemoveOrderResponse
} 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
  })
}
