package api

import (
	"gadmin/internal/admin/forms"
	"gadmin/internal/admin/service"
	"gadmin/utility/serializer"
	"github.com/gin-gonic/gin"
)

func LimitGiftList(c *gin.Context) {
	var req forms.LimitGiftListReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(200, ErrorResponse(err))
		return
	}
	if err := forms.ParseParams(&req); err != nil {
		c.JSON(200, ErrorResponse(err))
		return
	}

	if req.ServerId <= 0 {
		c.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
		return
	}

	resp, err := service.LimitGift.List(c, req)
	if err != nil {
		c.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = req.Page
	models.PerPage = req.PerPage
	models.PageCount = resp.Total / req.PerPage
	c.JSON(200, serializer.Suc(models))
}
