package rentComputer

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"log-server/global"
	"log-server/model/log/response"
	"log-server/model/rentComputer"
	"log-server/model/rentComputer/request"
	"log-server/utils"
)

type ApiRentSetMeal struct {
}

func (s *ApiRentSetMeal) GetRentSetMealList(c *gin.Context) {
	var paramsInfo request.GetStatisticsSetMealRequest
	_ = c.ShouldBindJSON(&paramsInfo)
	/*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}*/
	list, total, err := ServiceRentSetMeal.RentSetMealList(c, paramsInfo.RentSetMeal, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     paramsInfo.Page,
			PageSize: paramsInfo.PageSize,
		}, "获取成功", c)
	}
}

func (s *ApiRentSetMeal) GetRentSetMealNum(c *gin.Context) {
	//var paramsInfo request.GetStatisticsComputerShopRequest
	//_ = c.ShouldBindJSON(&paramsInfo)
	//num := ServiceComputerShop.GetComputerShopNum(paramsInfo.CreateTime)
	num := ServiceRentSetMeal.GetRentSetMealNum()
	response.OkWithDetailed(num, "获取成功", c)
}

func (s *ApiRentSetMeal) GetRentSetMealById(c *gin.Context) {
	var idInfo request.GetById
	_ = c.ShouldBindJSON(&idInfo)
	if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	api, err := ServiceRentSetMeal.GetRentSetMealById(idInfo.ID)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(api, "获取成功", c)
	}
}

func (s *ApiRentSetMeal) AddRentSetMeal(c *gin.Context) {
	var api request.SetMealRequest
	_ = c.ShouldBindJSON(&api)
	//if err := utils.Verify(api, utils.LogCodingVerify); err != nil {
	//	response.FailWithMessage(err.Error(), c)
	//	return
	//}
	fmt.Printf("%#v\n", &api)
	if err := ServiceRentSetMeal.AddRentSetMeal(api); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

func (s *ApiRentSetMeal) EditRentSetMeal(c *gin.Context) {
	var detail rentComputer.RentSetMeal
	_ = c.ShouldBindJSON(&detail)
	if err := ServiceRentSetMeal.EditRentSetMeal(detail); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

func (s *ApiRentSetMeal) DeleteRentSetMealByIds(c *gin.Context) {
	var ids request.IdsReq
	_ = c.ShouldBindJSON(&ids)
	if err := ServiceRentSetMeal.DeleteRentSetMealByIds(ids); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

func (s *ApiRentSetMeal) DeleteRentSetMealById(c *gin.Context) {
	var api rentComputer.RentSetMeal
	_ = c.ShouldBindJSON(&api)

	if err := ServiceRentSetMeal.DeleteRentSetMealById(api); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}
