import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { GltTicketOrder, GltTicketOrderParam } from './model';

/**
 * 分页查询送水订单
 */
export async function pageGltTicketOrder(params: GltTicketOrderParam) {
  const res = await request.get<ApiResult<PageResult<GltTicketOrder>>>(
    '/glt/glt-ticket-order/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询送水订单列表
 */
export async function listGltTicketOrder(params?: GltTicketOrderParam) {
  const res = await request.get<ApiResult<GltTicketOrder[]>>(
    '/glt/glt-ticket-order',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加送水订单
 */
export async function addGltTicketOrder(data: GltTicketOrder) {
  const res = await request.post<ApiResult<unknown>>(
    '/glt/glt-ticket-order',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改送水订单
 */
export async function updateGltTicketOrder(data: GltTicketOrder) {
  const res = await request.put<ApiResult<unknown>>(
    '/glt/glt-ticket-order',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除送水订单
 */
export async function removeGltTicketOrder(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/glt/glt-ticket-order/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除送水订单
 */
export async function removeBatchGltTicketOrder(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/glt/glt-ticket-order/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询送水订单
 */
export async function getGltTicketOrder(id: number) {
  const res = await request.get<ApiResult<GltTicketOrder>>(
    '/glt/glt-ticket-order/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
