package handler

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type reportParam struct {
	Player string `form:"player" binding:"required,notblank"`
	Turn   int    `form:"turn" binding:"gte=0"`
}

func ReportHandler(c *gin.Context, executor CommandExecutor) {
	p := &reportParam{}
	err := c.ShouldBindQuery(p)
	if errorResponse(c, err) {
		return
	}

	r, err := executor.LoadReport(p.Player, uint(p.Turn))
	if errorResponse(c, err) {
		return
	}

	c.JSON(http.StatusOK, r)
}
