package api

import (
	"errors"
	"gadmin/internal/admin/forms"
	"gadmin/internal/admin/service"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

func FightingList(c *gin.Context) {
	var req forms.FightingListReq
	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
	}

	c.JSON(200, service.Fighting.List(c, req))
}

func FightingExtra(c *gin.Context) {
	extraPath := c.DefaultQuery("extra_path", "")
	if extraPath == "" {
		c.JSON(200, ErrorResponse(errors.New("参数错误")))
	}
	c.JSON(200, service.Fighting.GetExtra(extraPath))
}

func FightingExport(c *gin.Context) {
	var req forms.FightingExportReq
	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
	}

	logrus.Warnf("FightingExport req:%+v", req)

	service.Fighting.Export(c, req)
}
