package api

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

func GetTreasureChestList(ctx *gin.Context) {
	var params forms.TreasureChestReportReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -7))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.TreasureChest.QueryTreasureChestList(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

func TreasureChest(ctx *gin.Context) {
	var params forms.TreasurePlayerLevelReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	resp, err := service.Treasure.PlayerLevel(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}
