import request from '@/config/axios'

// 统计查询参数
export interface StatisticsQuery {
  startTime?: Date
  endTime?: Date
  type?: string
}

// 物资柜使用情况统计
export interface CabinetStatisticsVO {
  totalCount: number
  usedCount: number
  availableCount: number
  maintenanceCount: number
}

// 物资借还统计
export interface MaterialsLoanStatisticsVO {
  totalCount: number
  loanedCount: number
  returnedCount: number
  overdueCount: number
}

// 物资状态统计
export interface MaterialsStatusStatisticsVO {
  totalCount: number
  normalCount: number
  abnormalCount: number
  maintenanceCount: number
}

// 物资更换统计
export interface MaterialsChangeStatisticsVO {
  totalCount: number
  changedCount: number
  unchangedCount: number
}

// 用户借还统计
export interface UserLoanStatisticsVO {
  userId: string
  userName: string
  loanCount: number
  returnCount: number
  overdueCount: number
}

// 每日借还统计
export interface DayLoanStatisticsVO {
  date: string
  loanCount: number
  returnCount: number
}

// 首页统计数据
export interface HomePageVO {
  cabinetStatistics: CabinetStatisticsVO
  materialsStatistics: MaterialsLoanStatisticsVO
  userStatistics: UserLoanStatisticsVO
  recentActivities: any[]
}

// 物资盘点统计
export interface MaterialInventoryVO {
  materialsId: number
  materialsName: string
  expectedCount: number
  actualCount: number
  difference: number
}

// 获取物资柜使用情况统计
export const getCabinetStatistics = async (params: StatisticsQuery) => {
  return await request.get<CabinetStatisticsVO>({
    url: '/iscs/statistics-api/getCabinetStatistics',
    params
  })
}

// 获取物资借还统计
export const getMaterialsLoanStatistics = async (params: StatisticsQuery) => {
  return await request.get<MaterialsLoanStatisticsVO>({
    url: '/iscs/statistics-api/getMaterialsLoanStatistics',
    params
  })
}

// 获取物资状态统计
export const getMaterialsStatusStatistics = async (params: StatisticsQuery) => {
  return await request.get<MaterialsStatusStatisticsVO>({
    url: '/iscs/statistics-api/getMaterialsStatusStatistics',
    params
  })
}

// 获取物资更换统计
export const getMaterialsChangeStatistics = async (params: StatisticsQuery) => {
  return await request.get<MaterialsChangeStatisticsVO>({
    url: '/iscs/statistics-api/getMaterialsChangeStatistics',
    params
  })
}

// 获取用户借还统计
export const getUserLoanStatistics = async (params: StatisticsQuery) => {
  return await request.get<UserLoanStatisticsVO[]>({
    url: '/iscs/statistics-api/getUserLoanStatistics',
    params
  })
}

// 获取每日借还统计
export const getDayLoanStatistics = async (params: StatisticsQuery) => {
  return await request.get<DayLoanStatisticsVO[]>({
    url: '/iscs/statistics-api/getDayLoanStatistics',
    params
  })
}

// 获取首页统计数据
export const getHomePage = async (params: StatisticsQuery) => {
  return await request.get<HomePageVO>({
    url: '/iscs/statistics-api/getHomePage',
    params
  })
}

// 获取物资盘点统计
export const getMaterialInventory = async (type: string) => {
  return await request.get<MaterialInventoryVO[]>({
    url: '/iscs/statistics-api/getMaterialInventory',
    params: { type }
  })
}

// 获取物资盘点总数
export const getInventorySum = async () => {
  return await request.get<{ total: number }>({
    url: '/iscs/statistics-api/getInventorySum'
  })
}
// 导出基础数据统计
export const exportBaseData = async (params) => {
  return await request.post({ url: `/iscs/statistics-api/exportBaseData`, params })
}
// 导出领取归还统计
export const exportClaimAndReturn = async (params) => {
  return await request.post({ url: `/iscs/statistics-api/exportClaimAndReturn`, params })
}
//导出物资盘点
export const exportMaterialInventory = async () => {
  return await request.post({ url: `/iscs/statistics-api/exportMaterialInventory` })
}
