import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  ReportQuery,
  ReturnReasonAnalysisVO,
  InventoryTrendAnalysisVO,
  SafetyStockAlertVO,
  StagnantInventoryVO,
  InventoryDifferenceVO,
  InventoryTurnoverVO
} from '@/api/wms/report/types';

/**
 * 查询退库原因分析报表
 * @param query
 * @returns {*}
 */
export const getReturnReasonAnalysis = (query?: ReportQuery): AxiosPromise<ReturnReasonAnalysisVO[]> => {
  return request({
    url: '/wms/report/returnReasonAnalysis',
    method: 'get',
    params: query
  });
};

/**
 * 导出退库原因分析报表
 * @param query
 */
export const exportReturnReasonAnalysis = (query?: ReportQuery) => {
  return request({
    url: '/wms/report/returnReasonAnalysis/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};

/**
 * 查询库存变动趋势分析报表
 * @param query
 * @returns {*}
 */
export const getInventoryTrendAnalysis = (query?: ReportQuery): AxiosPromise<InventoryTrendAnalysisVO[]> => {
  return request({
    url: '/wms/report/inventoryTrendAnalysis',
    method: 'get',
    params: query
  });
};

/**
 * 导出库存变动趋势分析报表
 * @param query
 */
export const exportInventoryTrendAnalysis = (query?: ReportQuery) => {
  return request({
    url: '/wms/report/inventoryTrendAnalysis/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};

/**
 * 查询安全库存预警报表
 * @param query
 * @returns {*}
 */
export const getSafetyStockAlert = (query?: ReportQuery): AxiosPromise<SafetyStockAlertVO[]> => {
  return request({
    url: '/wms/report/safetyStockAlert',
    method: 'get',
    params: query
  });
};

/**
 * 导出安全库存预警报表
 * @param query
 */
export const exportSafetyStockAlert = (query?: ReportQuery) => {
  return request({
    url: '/wms/report/safetyStockAlert/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};

/**
 * 查询呆滞料库存报表
 * @param query
 * @returns {*}
 */
export const getStagnantInventory = (query?: ReportQuery): AxiosPromise<StagnantInventoryVO[]> => {
  return request({
    url: '/wms/report/stagnantInventory',
    method: 'get',
    params: query
  });
};

/**
 * 导出呆滞料库存报表
 * @param query
 */
export const exportStagnantInventory = (query?: ReportQuery) => {
  return request({
    url: '/wms/report/stagnantInventory/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};

/**
 * 查询库存差异报表
 * @param query
 * @returns {*}
 */
export const getInventoryDifference = (query?: ReportQuery): AxiosPromise<InventoryDifferenceVO[]> => {
  return request({
    url: '/wms/report/inventoryDifference',
    method: 'get',
    params: query
  });
};

/**
 * 导出库存差异报表
 * @param query
 */
export const exportInventoryDifference = (query?: ReportQuery) => {
  return request({
    url: '/wms/report/inventoryDifference/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};

/**
 * 查询库存周转报表
 * @param query
 * @returns {*}
 */
export const getInventoryTurnover = (query?: ReportQuery): AxiosPromise<InventoryTurnoverVO[]> => {
  return request({
    url: '/wms/report/inventoryTurnover',
    method: 'get',
    params: query
  });
};

/**
 * 导出库存周转报表
 * @param query
 */
export const exportInventoryTurnover = (query?: ReportQuery) => {
  return request({
    url: '/wms/report/inventoryTurnover/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};