import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OrderVO, OrderForm, OrderQuery } from '@/api/order/types';

/**
 * 查询全部工单列表
 * @param query
 * @returns {*}
 */

export const listOrder = (query?: OrderQuery): AxiosPromise<{ records: OrderVO[] }> => {
  return request({
    url: '/work-order/list',
    method: 'post',
    data: query
  });
};

/**
 * 查询全部工单详细
 * @param id
 */
export const getOrder = (id?: string | number): AxiosPromise<OrderVO> => {
  return request({
    url: '/work-order/get-by-id?id=' + id,
    method: 'get'
  });
};

/**
 * 新增全部工单
 * @param data
 */
export const addOrder = (data: OrderForm) => {
  return request({
    url: '/work-order/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改全部工单
 * @param data
 */
export const updateOrder = (data: OrderForm) => {
  return request({
    url: '/order/order',
    method: 'put',
    data: data
  });
};

/**
 * 删除全部工单
 * @param id
 */
export const delOrder = (id: string | number | Array<string | number>) => {
  return request({
    url: '/work-order/delete',
    method: 'post',
    data: { id }
  });
};

// 工单用户查看列表
export const orderViewLog = (data: { workOrderId: string } & PageQuery) => {
  return request({
    url: '/work-order-view-log/list',
    method: 'post',
    data: data
  });
};

// 工单新增用户查看
export const orderAddLog = (id: string) => {
  return request({
    url: '/work-order-view-log/add',
    method: 'post',
    data: { workOrderId: id }
  });
};

// 变更工单状态
export const updateOrderStatus = (data: { id?: string, remark: string, orderType: number }) => {
  return request({
    url: '/work-order/update-status',
    method: 'post',
    data
  });
};

// 分配工单&转他人处理工单
export const distributionOrder = (data: { workOrderIds?: string, remark: string, ownerBy: string | number }) => {
  return request({
    url: '/work-order/distribution',
    method: 'post',
    data
  });
};
