package controller

import (
	"github.com/gin-gonic/gin"
	"iot_manager_service/app/middleware"
	edgeService "iot_manager_service/app/security/edge_service"
	"iot_manager_service/app/security/service"
	"iot_manager_service/util/common"
	"net/http"
	"strconv"
)

// TODO: 未记录日志
var Multiscreen = new(multiscreenCtl)

type multiscreenCtl struct{}

func (c *multiscreenCtl) Ptzhome(ctx *gin.Context) {
	code := ctx.Query("sn")
	name := ctx.Query("name")
	flag, _ := strconv.Atoi(ctx.Query("flag"))
	vidiconService := edgeService.ForVidiconService{}
	operate, err := vidiconService.Ptzhome(code, name, flag)
	if err != nil {
		ctx.JSON(http.StatusOK, err)
	}
	if !operate {
		ctx.JSON(http.StatusOK, nil)
		return
	}
	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, nil))
}

func (c *multiscreenCtl) List(ctx *gin.Context) {
	value, _ := ctx.Get(middleware.Authorization)
	claims := value.(*middleware.Claims)
	list, err := service.MultiscreenService.List(claims)
	if err != nil {
		ctx.JSON(http.StatusOK, err)
	}
	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, list))
}

func (c *multiscreenCtl) Submit(ctx *gin.Context) {
	value, _ := ctx.Get(middleware.Authorization)
	claims := value.(*middleware.Claims)
	site, _ := strconv.Atoi(ctx.Query("site"))
	id, _ := strconv.Atoi(ctx.Query("id"))
	service.MultiscreenService.Save(claims, site, id)
	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, nil))
}
