import {
  BaseListResult,
  BaseResult,
  GetInventoryChildListParams,
  GetInventoryDetailedListParams,
  GetInventoryMainListParams,
  InventoryChildListData,
  InventoryLogListData,
  InventoryMainListData,
} from '@models';
import {request} from './request';

export const BASE_URL = '/inventory';

/** 新增盘点表 */
export function addInventory(title: string): BaseResult {
  return request({
    method: 'POST',
    data: {title},
    url: `${BASE_URL}/addInventoryPlate`,
  });
}

/** 查询盘点主表 */
export function getInventoryMainList(
  data: GetInventoryMainListParams,
  signal?: AbortSignal,
): BaseListResult<InventoryMainListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getInventoryDataList`,
    signal,
  });
}

/** 查询盘点子表 */
export function getInventoryChildList(
  data: GetInventoryChildListParams,
  signal?: AbortSignal,
): BaseListResult<InventoryChildListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getInventoryPlates`,
    signal,
  });
}

/** 查询盘点明细表 */
export function getInventoryDetailedList(
  data: GetInventoryDetailedListParams,
  signal?: AbortSignal,
): BaseListResult<InventoryLogListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getInventory`,
    signal,
  });
}

/** 导出明细表 */
export function exportInventory(data: GetInventoryChildListParams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/export`,
    skipError: true,
  });
}

/** 导出录入明细 */
export function exportInventoryLog(data: GetInventoryDetailedListParams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/exportEntering`,
    skipError: true,
  });
}
