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

var voiceAddrService = service.ServiceGroupApp.AirDropServiceGroup.VoiceAddrService


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

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

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

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

// FindVoiceAddr 用id查询VoiceAddr
// @Tags VoiceAddr
// @Summary 用id查询VoiceAddr
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query airDrop.VoiceAddr true "用id查询VoiceAddr"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /voiceAddr/findVoiceAddr [get]
func (voiceAddrApi *VoiceAddrApi) FindVoiceAddr(c *gin.Context) {
	var voiceAddr airDrop.VoiceAddr
	err := c.ShouldBindQuery(&voiceAddr)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if revoiceAddr, err := voiceAddrService.GetVoiceAddr(voiceAddr.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"revoiceAddr": revoiceAddr}, c)
	}
}

// GetVoiceAddrList 分页获取VoiceAddr列表
// @Tags VoiceAddr
// @Summary 分页获取VoiceAddr列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query airDropReq.VoiceAddrSearch true "分页获取VoiceAddr列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /voiceAddr/getVoiceAddrList [get]
func (voiceAddrApi *VoiceAddrApi) GetVoiceAddrList(c *gin.Context) {
	var pageInfo airDropReq.VoiceAddrSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := voiceAddrService.GetVoiceAddrInfoList(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)
    }
}
