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"
	"courseSign/server/utils"
)

type PoolAddrWithdrawListApi struct {
}

var poolAddrWithdrawListService = service.ServiceGroupApp.EntrustPoolServiceGroup.PoolAddrWithdrawListService


// CreatePoolAddrWithdrawList 创建PoolAddrWithdrawList
// @Tags PoolAddrWithdrawList
// @Summary 创建PoolAddrWithdrawList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body entrustPool.PoolAddrWithdrawList true "创建PoolAddrWithdrawList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolAddrWithdrawList/createPoolAddrWithdrawList [post]
func (poolAddrWithdrawListApi *PoolAddrWithdrawListApi) CreatePoolAddrWithdrawList(c *gin.Context) {
	var poolAddrWithdrawList entrustPool.PoolAddrWithdrawList
	err := c.ShouldBindJSON(&poolAddrWithdrawList)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    verify := utils.Rules{
        "Addr":{utils.NotEmpty()},
        "Amount":{utils.NotEmpty()},
        "Height":{utils.NotEmpty()},
        "Hash":{utils.NotEmpty()},
        "WithdrawTime":{utils.NotEmpty()},
        "WithdrawDate":{utils.NotEmpty()},
    }
	if err := utils.Verify(poolAddrWithdrawList, verify); err != nil {
    		response.FailWithMessage(err.Error(), c)
    		return
    	}
	if err := poolAddrWithdrawListService.CreatePoolAddrWithdrawList(poolAddrWithdrawList); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

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

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

// UpdatePoolAddrWithdrawList 更新PoolAddrWithdrawList
// @Tags PoolAddrWithdrawList
// @Summary 更新PoolAddrWithdrawList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body entrustPool.PoolAddrWithdrawList true "更新PoolAddrWithdrawList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /poolAddrWithdrawList/updatePoolAddrWithdrawList [put]
func (poolAddrWithdrawListApi *PoolAddrWithdrawListApi) UpdatePoolAddrWithdrawList(c *gin.Context) {
	var poolAddrWithdrawList entrustPool.PoolAddrWithdrawList
	err := c.ShouldBindJSON(&poolAddrWithdrawList)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
      verify := utils.Rules{
          "Addr":{utils.NotEmpty()},
          "Amount":{utils.NotEmpty()},
          "Height":{utils.NotEmpty()},
          "Hash":{utils.NotEmpty()},
          "WithdrawTime":{utils.NotEmpty()},
          "WithdrawDate":{utils.NotEmpty()},
      }
    if err := utils.Verify(poolAddrWithdrawList, verify); err != nil {
      	response.FailWithMessage(err.Error(), c)
      	return
     }
	if err := poolAddrWithdrawListService.UpdatePoolAddrWithdrawList(poolAddrWithdrawList); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindPoolAddrWithdrawList 用id查询PoolAddrWithdrawList
// @Tags PoolAddrWithdrawList
// @Summary 用id查询PoolAddrWithdrawList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPool.PoolAddrWithdrawList true "用id查询PoolAddrWithdrawList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /poolAddrWithdrawList/findPoolAddrWithdrawList [get]
func (poolAddrWithdrawListApi *PoolAddrWithdrawListApi) FindPoolAddrWithdrawList(c *gin.Context) {
	var poolAddrWithdrawList entrustPool.PoolAddrWithdrawList
	err := c.ShouldBindQuery(&poolAddrWithdrawList)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if repoolAddrWithdrawList, err := poolAddrWithdrawListService.GetPoolAddrWithdrawList(poolAddrWithdrawList.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"repoolAddrWithdrawList": repoolAddrWithdrawList}, c)
	}
}

// GetPoolAddrWithdrawListList 分页获取PoolAddrWithdrawList列表
// @Tags PoolAddrWithdrawList
// @Summary 分页获取PoolAddrWithdrawList列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query entrustPoolReq.PoolAddrWithdrawListSearch true "分页获取PoolAddrWithdrawList列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolAddrWithdrawList/getPoolAddrWithdrawListList [get]
func (poolAddrWithdrawListApi *PoolAddrWithdrawListApi) GetPoolAddrWithdrawListList(c *gin.Context) {
	var pageInfo entrustPoolReq.PoolAddrWithdrawListSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := poolAddrWithdrawListService.GetPoolAddrWithdrawListInfoList(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)
    }
}

// GetPoolAddrWithdrawListListWeb 分页获取PoolAddrWithdrawList列表
// @Tags PoolAddrWithdrawList
// @Summary 分页获取PoolAddrWithdrawList列表
// @accept application/json
// @Produce application/json
// @Param data query entrustPoolReq.PoolAddrWithdrawListSearch true "分页获取PoolAddrWithdrawList列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /poolAddrWithdrawListWeb/getPoolAddrWithdrawListList [get]
func (poolAddrWithdrawListApi *PoolAddrWithdrawListApi) GetPoolAddrWithdrawListListWeb(c *gin.Context) {
	var pageInfo entrustPoolReq.PoolAddrWithdrawListSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if pageInfo.Addr == "" {
		response.FailWithMessage("addr is empty", c)
		return
	}
	if err := utils.Verify(pageInfo, utils.AddressVerify); err != nil {
		global.GVA_LOG.Error("GetPoolAddrWithdrawListListWeb verify err",zap.Error(err))
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := poolAddrWithdrawListService.GetPoolAddrWithdrawListInfoList(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)
	}
}
