package rentComputer

import (
	"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 ApiRentComputerShop struct {
}

func (s *ApiRentComputerShop) GetRentComputerShopList(c *gin.Context) {
	//global.GVA_LOG.Info("api----GetComputerShopList----strat")
	var paramsInfo request.GetStatisticsComputerShopRequest
	_ = c.ShouldBindJSON(&paramsInfo)
	/*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}*/
	list, total, err := ServiceRentComputerShop.RentComputerShopList(c, paramsInfo.RentComputerShop, 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 *ApiRentComputerShop) GetRentComputerShopNum(c *gin.Context) {
	//var paramsInfo request.GetStatisticsComputerShopRequest
	//_ = c.ShouldBindJSON(&paramsInfo)
	//num := ServiceComputerShop.GetComputerShopNum(paramsInfo.CreateTime)
	num := ServiceRentComputerShop.GetRentComputerShopNum()
	response.OkWithDetailed(num, "获取成功", c)
}

func (s *ApiRentComputerShop) GetRentComputerShopById(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 := ServiceRentComputerShop.GetRentComputerShopById(idInfo.ID)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(api, "获取成功", c)
	}
}

func (s *ApiRentComputerShop) AddRentComputerShop(c *gin.Context) {
	var api request.ComputerShopRequest
	_ = c.ShouldBindJSON(&api)
	//if err := utils.Verify(api, utils.LogCodingVerify); err != nil {
	//	response.FailWithMessage(err.Error(), c)
	//	return
	//}
	if err := ServiceRentComputerShop.AddRentComputerShop(api); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

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

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

func (s *ApiRentComputerShop) DeleteRentComputerShopById(c *gin.Context) {
	var api rentComputer.RentComputerShop
	_ = c.ShouldBindJSON(&api)

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