package entrustPool

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

type PoolRewardListApi struct {
}

var poolRewardListService = service.ServiceGroupApp.EntrustPoolServiceGroup.PoolRewardListService


// CreatePoolRewardList 创建PoolRewardList
// @Tags PoolRewardList
// @Summary 创建PoolRewardList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body entrustPool.PoolRewardList true "创建PoolRewardList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolRewardList/createPoolRewardList [post]
func (poolRewardListApi *PoolRewardListApi) CreatePoolRewardList(c *gin.Context) {
	var poolRewardList entrustPool.PoolRewardList
	err := c.ShouldBindJSON(&poolRewardList)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := poolRewardListService.CreatePoolRewardList(poolRewardList); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeletePoolRewardList 删除PoolRewardList
// @Tags PoolRewardList
// @Summary 删除PoolRewardList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body entrustPool.PoolRewardList true "删除PoolRewardList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /poolRewardList/deletePoolRewardList [delete]
func (poolRewardListApi *PoolRewardListApi) DeletePoolRewardList(c *gin.Context) {
	var poolRewardList entrustPool.PoolRewardList
	err := c.ShouldBindJSON(&poolRewardList)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := poolRewardListService.DeletePoolRewardList(poolRewardList); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

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

// UpdatePoolRewardList 更新PoolRewardList
// @Tags PoolRewardList
// @Summary 更新PoolRewardList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body entrustPool.PoolRewardList true "更新PoolRewardList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /poolRewardList/updatePoolRewardList [put]
func (poolRewardListApi *PoolRewardListApi) UpdatePoolRewardList(c *gin.Context) {
	var poolRewardList entrustPool.PoolRewardList
	err := c.ShouldBindJSON(&poolRewardList)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := poolRewardListService.UpdatePoolRewardList(poolRewardList); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindPoolRewardList 用id查询PoolRewardList
// @Tags PoolRewardList
// @Summary 用id查询PoolRewardList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPool.PoolRewardList true "用id查询PoolRewardList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /poolRewardList/findPoolRewardList [get]
func (poolRewardListApi *PoolRewardListApi) FindPoolRewardList(c *gin.Context) {
	var poolRewardList entrustPool.PoolRewardList
	err := c.ShouldBindQuery(&poolRewardList)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if repoolRewardList, err := poolRewardListService.GetPoolRewardList(poolRewardList.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"repoolRewardList": repoolRewardList}, c)
	}
}

// GetPoolRewardListList 分页获取PoolRewardList列表
// @Tags PoolRewardList
// @Summary 分页获取PoolRewardList列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPoolReq.PoolRewardListSearch true "分页获取PoolRewardList列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolRewardList/getPoolRewardListList [get]
func (poolRewardListApi *PoolRewardListApi) GetPoolRewardListList(c *gin.Context) {
	var pageInfo entrustPoolReq.PoolRewardListSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := poolRewardListService.GetPoolRewardListInfoList(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)
    }
}
