import {
  BaseListResult,
  BaseResult,
  GetReceiveListParams,
  GetReceiveOrderListParams,
  GetTimeoutReceiveListParams,
  ReceiveListData,
} from '@models';
import {request} from './request';

const BASE_URL = '/receiveGoods';

/** 获取质检单列表 */
export function getReceiveList(
  data: GetReceiveListParams,
  signal?: AbortSignal,
): BaseListResult<ReceiveListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getReceiveGoods`,
    signal,
  });
}

/**
 * @deprecated
 *  获取已过期采购单列表 */
export function getTimeoutReceiveList(
  data: GetTimeoutReceiveListParams,
): BaseListResult<ReceiveListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getPastReceiveGoods`,
  });
}

/** 获取采购单列表 */
export function getReceiveOrderList(
  data: GetReceiveOrderListParams,
  signal?: AbortSignal,
): BaseListResult<ReceiveListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getPurchase`,
    signal,
  });
}

/** 获取逾期采购单列表 */
export function getTimeoutReceiveOrderList(
  data: GetReceiveOrderListParams,
  signal?: AbortSignal,
): BaseListResult<ReceiveListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/timeoutPurchase`,
    signal,
  });
}

/** 质检单删除 */
export function delReceiveOrder(id: string): BaseResult {
  return request({
    method: 'DELETE',
    data: {id},
    url: `${BASE_URL}/delReceiveGoods`,
  });
}

/** 导出采购单 */
export function exportReceive(data: GetReceiveOrderListParams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/purchaseExport`,
  });
}

/** 导出逾期采购单 */
export function exportTimeoutReceive(data: GetReceiveOrderListParams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/overtimePurchaseExport`,
  });
}
