import { requestClient } from '#/api/request';

export namespace MesSafetyStatisticsApi {
  /** 查询参数 */
  export interface StatisticsParam {
    startDate?: string;
    endDate?: string;
    workshopId?: number;
  }

  /** 汇总指标 */
  export interface Summary {
    hazardTotal: number;
    hazardClosed: number;
    hazardClosedRate: number;
    hazardOverdue: number;
    ticketTotal: number;
    ticketArchived: number;
    ticketRejected: number;
    trainingTotal: number;
    trainingAttendee: number;
    trainingAvgScore?: number;
    certificateTotal: number;
    certificateExpired: number;
  }

  /** 分组统计项 */
  export interface GroupStat {
    name: string;
    code?: number;
    total: number;
    finished?: number;
    finishRate?: number;
    attendeeTotal?: number;
    avgScore?: number;
  }

  /** 统计报表 */
  export interface StatisticsReport {
    summary: Summary;
    hazardByWorkshop: GroupStat[];
    hazardByLevel: GroupStat[];
    hazardBySource: GroupStat[];
    ticketByType: GroupStat[];
    ticketByStatus: GroupStat[];
    trainingByType: GroupStat[];
    certificateByType: GroupStat[];
  }
}

/** 获得安全生产统计报表 */
export function getStatisticsReport(params: MesSafetyStatisticsApi.StatisticsParam) {
  return requestClient.get<MesSafetyStatisticsApi.StatisticsReport>(
    '/mes/safety/statistics/report',
    { params },
  );
}

/** 导出隐患明细 */
export function exportHazardDetail(params: MesSafetyStatisticsApi.StatisticsParam) {
  return requestClient.download('/mes/safety/statistics/export-hazard', { params });
}
