package course

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

type CourseBannersApi struct {
}

var courseBannersService = service.ServiceGroupApp.CourseServiceGroup.CourseBannersService


// CreateCourseBanners 创建CourseBanners
// @Tags CourseBanners
// @Summary 创建CourseBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body course.CourseBanners true "创建CourseBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /courseBanners/createCourseBanners [post]
func (courseBannersApi *CourseBannersApi) CreateCourseBanners(c *gin.Context) {
	var courseBanners course.CourseBanners
	err := c.ShouldBindJSON(&courseBanners)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := courseBannersService.CreateCourseBanners(courseBanners); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteCourseBanners 删除CourseBanners
// @Tags CourseBanners
// @Summary 删除CourseBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body course.CourseBanners true "删除CourseBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /courseBanners/deleteCourseBanners [delete]
func (courseBannersApi *CourseBannersApi) DeleteCourseBanners(c *gin.Context) {
	var courseBanners course.CourseBanners
	err := c.ShouldBindJSON(&courseBanners)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := courseBannersService.DeleteCourseBanners(courseBanners); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

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

// UpdateCourseBanners 更新CourseBanners
// @Tags CourseBanners
// @Summary 更新CourseBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body course.CourseBanners true "更新CourseBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /courseBanners/updateCourseBanners [put]
func (courseBannersApi *CourseBannersApi) UpdateCourseBanners(c *gin.Context) {
	var courseBanners course.CourseBanners
	err := c.ShouldBindJSON(&courseBanners)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := courseBannersService.UpdateCourseBanners(courseBanners); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindCourseBanners 用id查询CourseBanners
// @Tags CourseBanners
// @Summary 用id查询CourseBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query course.CourseBanners true "用id查询CourseBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /courseBanners/findCourseBanners [get]
func (courseBannersApi *CourseBannersApi) FindCourseBanners(c *gin.Context) {
	var courseBanners course.CourseBanners
	err := c.ShouldBindQuery(&courseBanners)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if recourseBanners, err := courseBannersService.GetCourseBanners(courseBanners.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"recourseBanners": recourseBanners}, c)
	}
}

// GetCourseBannersList 分页获取CourseBanners列表
// @Tags CourseBanners
// @Summary 分页获取CourseBanners列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query courseReq.CourseBannersSearch true "分页获取CourseBanners列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /courseBanners/getCourseBannersList [get]
func (courseBannersApi *CourseBannersApi) GetCourseBannersList(c *gin.Context) {
	var pageInfo courseReq.CourseBannersSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := courseBannersService.GetCourseBannersInfoList(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)
    }
}

// GetCourseBannersListWeb 分页获取CourseBanners列表
// @Tags CourseBanners
// @Summary 分页获取CourseBanners列表
// @accept application/json
// @Produce application/json
// @Param data query courseReq.CourseBannersSearch true "分页获取CourseBanners列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /courseBanners/getBanners [get]
func (courseBannersApi *CourseBannersApi) GetCourseBannersListWeb(c *gin.Context) {
	var pageInfo courseReq.CourseBannersSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := courseBannersService.GetCourseBannersInfoList(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)
	}
}
