import request from '@/utils/request';
import { AxiosPromise } from 'axios';

export interface BoardEnergyCompareVO {
  unit: string;
  xAxis: string[];
  today: number[];
  yesterday: number[];
}

export interface BoardTimeShareItemVO {
  name: '平' | '峰' | '谷';
  value: number;
  percent: number;
  color: string;
}

export interface BoardTimeShareVO {
  unit: string;
  total: number;
  items: BoardTimeShareItemVO[];
}

export interface BoardDeviceStatusVO {
  deviceType: string | number;
  total: number;
  online: number;
  alarm: number;
  onlineRate: number;
  alarmRate: number;
}

export interface BoardAlarmEventVO {
  id: string | number;
  alarmDeviceName?: string;
  alarmTime?: string;
  alarmDetail?: string;
}

export interface BoardAlarmOverviewVO {
  period: 'today' | 'month';
  total: number;
  handled: number;
  unhandled: number;
  events: BoardAlarmEventVO[];
}

export const getBoardEnergyCompare = (params?: { date?: string }): AxiosPromise<BoardEnergyCompareVO> => {
  return request({
    url: '/ems/board/energyCompare',
    method: 'get',
    params
  });
};

export const getBoardDeviceStatus = (params?: { deviceType?: string | number }): AxiosPromise<BoardDeviceStatusVO> => {
  return request({
    url: '/ems/board/deviceStatus',
    method: 'get',
    params
  });
};

export const getBoardAlarmOverview = (params?: { period?: 'today' | 'month' }): AxiosPromise<BoardAlarmOverviewVO> => {
  return request({
    url: '/ems/board/alarmOverview',
    method: 'get',
    params
  });
};

export const getBoardTimeShare = (params?: { date?: string }): AxiosPromise<BoardTimeShareVO> => {
  return request({
    url: '/ems/board/timeShare',
    method: 'get',
    params
  });
};
