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 PoolAddrTxsApi struct {
}

var poolAddrTxsService = service.ServiceGroupApp.EntrustPoolServiceGroup.PoolAddrTxsService


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

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

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

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

// FindPoolAddrTxs 用id查询PoolAddrTxs
// @Tags PoolAddrTxs
// @Summary 用id查询PoolAddrTxs
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPool.PoolAddrTxs true "用id查询PoolAddrTxs"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /poolAddrTxs/findPoolAddrTxs [get]
func (poolAddrTxsApi *PoolAddrTxsApi) FindPoolAddrTxs(c *gin.Context) {
	var poolAddrTxs entrustPool.PoolAddrTxs
	err := c.ShouldBindQuery(&poolAddrTxs)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if repoolAddrTxs, err := poolAddrTxsService.GetPoolAddrTxs(poolAddrTxs.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"repoolAddrTxs": repoolAddrTxs}, c)
	}
}

// GetPoolAddrTxsList 分页获取PoolAddrTxs列表
// @Tags PoolAddrTxs
// @Summary 分页获取PoolAddrTxs列表
// @accept application/json
// @Produce application/json
// @Param data query entrustPoolReq.PoolAddrTxsSearch true "分页获取PoolAddrTxs列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolTxsWeb/getPoolAddrTxsList [get]
func (poolAddrTxsApi *PoolAddrTxsApi) GetPoolAddrTxsList(c *gin.Context) {
	var pageInfo entrustPoolReq.PoolAddrTxsSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := poolAddrTxsService.GetPoolAddrTxsInfoList(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)
    }
}

// GetPoolAddrTxsList2 分页获取PoolAddrTxs列表
// @Tags PoolAddrTxs2
// @Summary 分页获取PoolAddrTxs列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPoolReq.PoolAddrTxsSearch true "分页获取PoolAddrTxs列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolAddrTxs/getPoolAddrTxsList [get]
func (poolAddrTxsApi *PoolAddrTxsApi) GetPoolAddrTxsList2(c *gin.Context) {
	var pageInfo entrustPoolReq.PoolAddrTxsSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := poolAddrTxsService.GetPoolAddrTxsInfoList2(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)
	}
}