package service

import (
	"iot_manager_service/app/operation/dao"
	"iot_manager_service/app/operation/model"
	"iot_manager_service/app/warn/service"
)

var DeviceCountService = new(deviceCountService)

type deviceCountService struct{}

func (s deviceCountService) CountDevice(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
	list := dao.ViewsAllCodeDevice{
		TenantId: tenantId,
	}
	// TODO: 在线数 未做
	counts, err := list.GetDeviceCount()
	for i, count := range counts {
		warnCount, _ := service.PlatformAlarmService.GetWarnCount(tenantId, count.DeviceType)
		counts[i].AlarmCountT = int(warnCount)
		counts[i].OffLineCountT = 0 // 在线数 未做
	}
	if err != nil {
		return nil, err
	}
	return counts, nil
}

func (s deviceCountService) GetYearList(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
	list := dao.ViewsAllCodeDevice{
		TenantId: tenantId,
	}
	return list.GetYearDeviceCount(req)
}

func (s deviceCountService) GetMonthList(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
	list := dao.ViewsAllCodeDevice{
		TenantId: tenantId,
	}
	return list.GetMonthDeviceCount(req)
}

func (s deviceCountService) GetDayList(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
	list := dao.ViewsAllCodeDevice{
		TenantId: tenantId,
	}
	return list.GetDayDeviceCount(req)
}
