import {commonApi} from '@tuya/tuya-panel-api'

export interface PagingResult<T> {
  data: T
  hasNext: boolean
  currentOffset: number
}

export interface DpReportSataResData {
  dps: DpReportSataData[]
  hasNext: boolean
  total: number
}

export interface DpReportSataData {
  timeStamp: number
  dpId: number
  timeStr: string
  value: string
}

export async function getDpReportSataData(
  deviceId: string,
  dpIds: string[],
  offset: number,
  limit: number,
  sortType?: 'ASC' | 'DESC',
): Promise<DpReportSataResData> {
  const params = {
    devId: deviceId,
    dpIds: dpIds.join(','),
    offset: offset,
    limit: limit,
    sortType: sortType || 'DESC',
  }
  return commonApi.statApi.getDpReportLog(params)
}

export interface DpResultByMonthResData {
  years: object;
  thisDay: string;
  sum: string;
}

export async function getDpResultByMonth(
  devId: string,
  dpId: string,
  type: 'sum' | 'minux' | 'mac',
): Promise<DpResultByMonthResData> {
  const params = {
    devId,
    dpId,
    type,
  }
  return commonApi.statApi.getDpResultByMonth(params) as any
}

export interface DpResultByDataWithSpecifiedResData {
  result: object;
  min: string;
}

export async function getDataWithSpecified(
  devId: string,
  dpId: string,
  startDay: string,
  endDay: string,
  type: 'sum' | 'minux' | 'avg',
): Promise<DpResultByDataWithSpecifiedResData> {
  const params = {
    devId,
    dpId,
    startDay,
    endDay,
    type,
  }
  return commonApi.statApi.getDataWithSpecified(params) as any
}

export async function getDpResultByHour(
  devId: string,
  dpId: string,
  date: string,
  type: 'sum' | 'minux' | 'avg',
): Promise<DpResultByDataWithSpecifiedResData> {
  const params = {
    devId,
    dpId,
    date,
    type,
  }
  return commonApi.statApi.getDpResultByHour(params) as any
}