package airDrop

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

type VoiceVerifyApi struct {
}

var voiceVerifyService = service.ServiceGroupApp.AirDropServiceGroup.VoiceVerifyService


// CreateVoiceVerify 创建VoiceVerify
// @Tags VoiceVerify
// @Summary 创建VoiceVerify
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body airDrop.VoiceVerify true "创建VoiceVerify"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /voiceVerify/createVoiceVerify [post]
func (voiceVerifyApi *VoiceVerifyApi) CreateVoiceVerify(c *gin.Context) {
	var voiceVerify airDrop.VoiceVerify
	err := c.ShouldBindJSON(&voiceVerify)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := voiceVerifyService.CreateVoiceVerify(voiceVerify); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteVoiceVerify 删除VoiceVerify
// @Tags VoiceVerify
// @Summary 删除VoiceVerify
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body airDrop.VoiceVerify true "删除VoiceVerify"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /voiceVerify/deleteVoiceVerify [delete]
func (voiceVerifyApi *VoiceVerifyApi) DeleteVoiceVerify(c *gin.Context) {
	var voiceVerify airDrop.VoiceVerify
	err := c.ShouldBindJSON(&voiceVerify)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := voiceVerifyService.DeleteVoiceVerify(voiceVerify); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

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

// UpdateVoiceVerify 更新VoiceVerify
// @Tags VoiceVerify
// @Summary 更新VoiceVerify
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body airDrop.VoiceVerify true "更新VoiceVerify"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /voiceVerify/updateVoiceVerify [put]
func (voiceVerifyApi *VoiceVerifyApi) UpdateVoiceVerify(c *gin.Context) {
	var voiceVerify airDrop.VoiceVerify
	err := c.ShouldBindJSON(&voiceVerify)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := voiceVerifyService.UpdateVoiceVerify(voiceVerify); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindVoiceVerify 用id查询VoiceVerify
// @Tags VoiceVerify
// @Summary 用id查询VoiceVerify
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query airDrop.VoiceVerify true "用id查询VoiceVerify"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /voiceVerify/findVoiceVerify [get]
func (voiceVerifyApi *VoiceVerifyApi) FindVoiceVerify(c *gin.Context) {
	var voiceVerify airDrop.VoiceVerify
	err := c.ShouldBindQuery(&voiceVerify)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if revoiceVerify, err := voiceVerifyService.GetVoiceVerify(voiceVerify.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"revoiceVerify": revoiceVerify}, c)
	}
}

// GetVoiceVerifyList 分页获取VoiceVerify列表
// @Tags VoiceVerify
// @Summary 分页获取VoiceVerify列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query airDropReq.VoiceVerifySearch true "分页获取VoiceVerify列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /voiceVerify/getVoiceVerifyList [get]
func (voiceVerifyApi *VoiceVerifyApi) GetVoiceVerifyList(c *gin.Context) {
	var pageInfo airDropReq.VoiceVerifySearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := voiceVerifyService.GetVoiceVerifyInfoList(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)
    }
}
