package entrustPool

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/entrustPool"
	entrustPoolReq "courseSign/server/model/entrustPool/request"
	"courseSign/server/service"
)

type PoolConfigApi struct {
}

var poolConfigService = service.ServiceGroupApp.EntrustPoolServiceGroup.PoolConfigService


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

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

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

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

// FindPoolConfig 用id查询PoolConfig
// @Tags PoolConfig
// @Summary 用id查询PoolConfig
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPool.PoolConfig true "用id查询PoolConfig"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /poolConfig/findPoolConfig [get]
func (poolConfigApi *PoolConfigApi) FindPoolConfig(c *gin.Context) {
	var poolConfig entrustPool.PoolConfig
	err := c.ShouldBindQuery(&poolConfig)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if repoolConfig, err := poolConfigService.GetPoolConfig(poolConfig.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"repoolConfig": repoolConfig}, c)
	}
}

// GetPoolConfigList 分页获取PoolConfig列表
// @Tags PoolConfig
// @Summary 分页获取PoolConfig列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPoolReq.PoolConfigSearch true "分页获取PoolConfig列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolConfig/getPoolConfigList [get]
func (poolConfigApi *PoolConfigApi) GetPoolConfigList(c *gin.Context) {
	var pageInfo entrustPoolReq.PoolConfigSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := poolConfigService.GetPoolConfigInfoList(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)
    }
}
