package api

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

func GetTreasureList(ctx *gin.Context) {
	var params forms.TreasureReportReq
	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, -1))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.Treasure.QueryTreasureLog(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 TreasurePlayerLevel(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})
}

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

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

	resp, err := service.Treasure.Level(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 TreasureStar(ctx *gin.Context) {
	var params forms.TreasureStarReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

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