import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { OrderForm, OrderInfo, OrderInfoPageVO, OrderInfoQuery } from "./types";

/**
 * 获取订单分页列表
 *
 * @param queryParams
 */
export function getOrderPage(
  queryParams: object
): AxiosPromise<PageResult<OrderInfoPageVO[]>> {
  return request({
    url: "/api/v1/plan/order/page",
    method: "post",
    data: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getExpandAlias(tableType: String): AxiosPromise<any> {
  return request({
    url: "/api/v1/sys/alias/queryByType/" + tableType,
    method: "get",
  });
}

/**
 * 添加订单
 *
 * @param data
 */
export function addOrder(data: any) {
  return request({
    url: "/api/v1/plan/order/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改订单
 *
 * @param id
 * @param data
 */
export function updateOrder(data: OrderForm) {
  return request({
    url: "/api/v1/plan/order/update",
    method: "post",
    data: data,
  });
}

/**
 * 删除订单
 *
 * @param ids
 */
export function deleteOrders(ids: string[]) {
  return request({
    url: "/api/v1/plan/order/batch-del",
    method: "post",
    data: { ids: ids },
  });
}

/**
 * 下载导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
  return request({
    url: "/api/v1/plan/order/template",
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 导出
 *
 * @param queryParams
 * @returns
 */
export function exportOrder(queryParams: OrderInfoQuery) {
  return request({
    url: "/api/v1/plan/order/export",
    method: "post",
    data: queryParams,
    responseType: "arraybuffer",
  });
}

/**
 * 导入
 *
 * @param file
 */
export function importOrder(importData: any) {
  return request({
    url: "/api/v1/plan/order/import",
    method: "post",
    data: importData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}
