package user

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

type UsersMsgApi struct {
}

var usersMsgService = service.ServiceGroupApp.UserServiceGroup.UsersMsgService


// CreateUsersMsg 创建UsersMsg
// @Tags UsersMsg
// @Summary 创建UsersMsg
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body user.UsersMsg true "创建UsersMsg"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /usersMsg/createUsersMsg [post]
func (usersMsgApi *UsersMsgApi) CreateUsersMsg(c *gin.Context) {
	var usersMsg user.UsersMsg
	err := c.ShouldBindJSON(&usersMsg)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := usersMsgService.CreateUsersMsg(usersMsg); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteUsersMsg 删除UsersMsg
// @Tags UsersMsg
// @Summary 删除UsersMsg
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body user.UsersMsg true "删除UsersMsg"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /usersMsg/deleteUsersMsg [delete]
func (usersMsgApi *UsersMsgApi) DeleteUsersMsg(c *gin.Context) {
	var usersMsg user.UsersMsg
	err := c.ShouldBindJSON(&usersMsg)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := usersMsgService.DeleteUsersMsg(usersMsg); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

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

// UpdateUsersMsg 更新UsersMsg
// @Tags UsersMsg
// @Summary 更新UsersMsg
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body user.UsersMsg true "更新UsersMsg"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /usersMsg/updateUsersMsg [put]
func (usersMsgApi *UsersMsgApi) UpdateUsersMsg(c *gin.Context) {
	var usersMsg user.UsersMsg
	err := c.ShouldBindJSON(&usersMsg)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := usersMsgService.UpdateUsersMsg(usersMsg); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindUsersMsg 用id查询UsersMsg
// @Tags UsersMsg
// @Summary 用id查询UsersMsg
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.UsersMsg true "用id查询UsersMsg"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /usersMsg/findUsersMsg [get]
func (usersMsgApi *UsersMsgApi) FindUsersMsg(c *gin.Context) {
	var usersMsg user.UsersMsg
	err := c.ShouldBindQuery(&usersMsg)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if reusersMsg, err := usersMsgService.GetUsersMsg(usersMsg.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reusersMsg": reusersMsg}, c)
	}
}

// GetUsersMsgList 分页获取UsersMsg列表
// @Tags UsersMsg
// @Summary 分页获取UsersMsg列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query userReq.UsersMsgSearch true "分页获取UsersMsg列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /usersMsg/getUsersMsgList [get]
func (usersMsgApi *UsersMsgApi) GetUsersMsgList(c *gin.Context) {
	var pageInfo userReq.UsersMsgSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := usersMsgService.GetUsersMsgInfoList(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)
    }
}

// SendUsersMsg 发送UsersMsg
// @Tags UsersMsg
// @Summary 发送UsersMsg
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body user.UsersMsg true "发送UsersMsg"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /usersMsg/createUsersMsg [post]
func (usersMsgApi *UsersMsgApi) SendUsersMsg(c *gin.Context) {
	var usersMsg user.UsersMsg
	err := c.ShouldBindJSON(&usersMsg)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := usersMsgService.CreateUsersMsg(usersMsg); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}
