package controller

import (
	"github.com/gin-gonic/gin"
	"iot_manager_service/app/operation/service"
	"iot_manager_service/util/common"
	"net/http"
	"strconv"
)

var Manhole = new(manholeCtl)

type manholeCtl struct{}

func (c *manholeCtl) HistoryList(ctx *gin.Context) {
	id, _ := strconv.Atoi(ctx.Query("id"))
	queryStartDate := ctx.Query("queryStartDate")
	queryEndDate := ctx.Query("queryEndDate")
	queryType := ctx.Query("queryType")

	record, err := service.AepCallbackRecordService.GetHistoryList(id, queryStartDate, queryEndDate, queryType)
	if err != nil {
		ctx.JSON(http.StatusOK, err)
		return
	}
	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, record))
}

func (c *manholeCtl) LiveData(ctx *gin.Context) {
	id, _ := strconv.Atoi(ctx.Query("id"))
	record, err := service.AepCallbackRecordService.GetByDeviceId(id)
	if err != nil {
		ctx.JSON(http.StatusOK, err)
		return
	}
	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, record))
}
