package twi

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"courseSign/server/global"
	"courseSign/server/model/common/request"
	"courseSign/server/model/common/response"
	"courseSign/server/model/twi"
	twiReq "courseSign/server/model/twi/request"
	"courseSign/server/service"
	"courseSign/server/utils"
)

type ActBannerApi struct {
}

var actBannerService = service.ServiceGroupApp.TwiServiceGroup.ActBannerService


// CreateActBanner 创建ActBanner
// @Tags ActBanner
// @Summary 创建ActBanner
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body twi.ActBanner true "创建ActBanner"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /actBanner/createActBanner [post]
func (actBannerApi *ActBannerApi) CreateActBanner(c *gin.Context) {
	var actBanner twi.ActBanner
	err := c.ShouldBindJSON(&actBanner)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    verify := utils.Rules{
        "ActName":{utils.NotEmpty()},
    }
	if err := utils.Verify(actBanner, verify); err != nil {
    		response.FailWithMessage(err.Error(), c)
    		return
    	}
	if err := actBannerService.CreateActBanner(actBanner); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteActBanner 删除ActBanner
// @Tags ActBanner
// @Summary 删除ActBanner
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body twi.ActBanner true "删除ActBanner"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /actBanner/deleteActBanner [delete]
func (actBannerApi *ActBannerApi) DeleteActBanner(c *gin.Context) {
	var actBanner twi.ActBanner
	err := c.ShouldBindJSON(&actBanner)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := actBannerService.DeleteActBanner(actBanner); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteActBannerByIds 批量删除ActBanner
// @Tags ActBanner
// @Summary 批量删除ActBanner
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ActBanner"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /actBanner/deleteActBannerByIds [delete]
func (actBannerApi *ActBannerApi) DeleteActBannerByIds(c *gin.Context) {
	var IDS request.IdsReq
    err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := actBannerService.DeleteActBannerByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateActBanner 更新ActBanner
// @Tags ActBanner
// @Summary 更新ActBanner
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body twi.ActBanner true "更新ActBanner"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /actBanner/updateActBanner [put]
func (actBannerApi *ActBannerApi) UpdateActBanner(c *gin.Context) {
	var actBanner twi.ActBanner
	err := c.ShouldBindJSON(&actBanner)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
      verify := utils.Rules{
          "ActName":{utils.NotEmpty()},
      }
    if err := utils.Verify(actBanner, verify); err != nil {
      	response.FailWithMessage(err.Error(), c)
      	return
     }
	if err := actBannerService.UpdateActBanner(actBanner); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindActBanner 用id查询ActBanner
// @Tags ActBanner
// @Summary 用id查询ActBanner
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query twi.ActBanner true "用id查询ActBanner"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /actBanner/findActBanner [get]
func (actBannerApi *ActBannerApi) FindActBanner(c *gin.Context) {
	var actBanner twi.ActBanner
	err := c.ShouldBindQuery(&actBanner)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if reactBanner, err := actBannerService.GetActBanner(actBanner.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reactBanner": reactBanner}, c)
	}
}

// GetActBannerList 分页获取ActBanner列表
// @Tags ActBanner
// @Summary 分页获取ActBanner列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query twiReq.ActBannerSearch true "分页获取ActBanner列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /actBanner/getActBannerList [get]
func (actBannerApi *ActBannerApi) GetActBannerList(c *gin.Context) {
	var pageInfo twiReq.ActBannerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := actBannerService.GetActBannerInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}

// GetActBannerListWeb web获取ActBanner列表
// @Tags ActBanner
// @Summary 分页获取ActBanner列表
// @accept application/json
// @Produce application/json
// @Param data query twiReq.ActBannerSearch true "web获取ActBanner列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /actBanner/list [get]
func (actBannerApi *ActBannerApi) GetActBannerListWeb(c *gin.Context) {
	var pageInfo twiReq.ActBannerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := actBannerService.GetActBannerInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
