package app

import (
	"ln/nft/global"
	"ln/nft/model/app"
	appReq "ln/nft/model/app/request"
	"ln/nft/model/common/request"
	"ln/nft/model/common/response"
	"ln/nft/service"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type AppBannersApi struct {
}

var appBannersService = service.ServiceGroupApp.AppServiceGroup.AppBannersService

// CreateAppBanners 创建AppBanners
// @Tags AppBanners
// @Summary 创建AppBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body app.AppBanners true "创建AppBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /appBanners/createAppBanners [post]
func (appBannersApi *AppBannersApi) CreateAppBanners(c *gin.Context) {
	var appBanners app.AppBanners
	_ = c.ShouldBindJSON(&appBanners)
	if err := appBannersService.CreateAppBanners(appBanners); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteAppBanners 删除AppBanners
// @Tags AppBanners
// @Summary 删除AppBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body app.AppBanners true "删除AppBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /appBanners/deleteAppBanners [delete]
func (appBannersApi *AppBannersApi) DeleteAppBanners(c *gin.Context) {
	var appBanners app.AppBanners
	_ = c.ShouldBindJSON(&appBanners)
	if err := appBannersService.DeleteAppBanners(appBanners); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

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

// UpdateAppBanners 更新AppBanners
// @Tags AppBanners
// @Summary 更新AppBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body app.AppBanners true "更新AppBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /appBanners/updateAppBanners [put]
func (appBannersApi *AppBannersApi) UpdateAppBanners(c *gin.Context) {
	var appBanners app.AppBanners
	_ = c.ShouldBindJSON(&appBanners)
	if err := appBannersService.UpdateAppBanners(appBanners); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindAppBanners 用id查询AppBanners
// @Tags AppBanners
// @Summary 用id查询AppBanners
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query app.AppBanners true "用id查询AppBanners"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /appBanners/findAppBanners [get]
func (appBannersApi *AppBannersApi) FindAppBanners(c *gin.Context) {
	var appBanners app.AppBanners
	_ = c.ShouldBindQuery(&appBanners)
	if reappBanners, err := appBannersService.GetAppBanners(appBanners.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reappBanners": reappBanners}, c)
	}
}

// GetAppBannersList 分页获取AppBanners列表
// @Tags AppBanners
// @Summary 分页获取AppBanners列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query appReq.AppBannersSearch true "分页获取AppBanners列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /appBanners/getAppBannersList [get]
func (appBannersApi *AppBannersApi) GetAppBannersList(c *gin.Context) {
	var pageInfo appReq.AppBannersSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if list, total, err := appBannersService.GetAppBannersInfoList(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)
	}
}
