package devices

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"server/global"
	"server/model/common/response"
	"server/model/devices"
)

type ProgramApi struct{}

func (pa *ProgramApi) CreateProgram(c *gin.Context) {
	var info devices.ProgramReq
	if err := c.ShouldBindJSON(&info); err != nil {
		global.GVA_LOG.Error("CreateProgram === ", zap.Error(err))
		response.FailWithMessage("参数错误", c)
		return
	}
	err := programService.CreateProgram(info)
	if err != nil {
		global.GVA_LOG.Error("CreateProgram === ", zap.Error(err))
		response.FailWithMessage("新增失败", c)
		return
	}

	response.Ok(c)
}

func (pa *ProgramApi) UpdateProgram(c *gin.Context) {
	var info devices.ProgramReq
	if err := c.ShouldBindJSON(&info); err != nil {
		global.GVA_LOG.Error("UpdateProgram === ", zap.Error(err))
		response.FailWithMessage("参数错误", c)
		return
	}
	err := programService.UpdateProgram(info)
	if err != nil {
		global.GVA_LOG.Error("UpdateProgram === ", zap.Error(err))
		response.FailWithMessage("更新失败", c)
		return
	}

	response.Ok(c)
}
