package plan_replayer

import (
	"github.com/gin-gonic/gin"

	"github.com/pingcap-inc/clinic/pkg/ngm/file_download"
	_ "github.com/pingcap-inc/clinic/pkg/ngm/file_download/api"
	"github.com/pingcap-inc/clinic/pkg/ngm/storage"
)

func InitPlanReplayerApi(g *gin.RouterGroup, service *Service) {
	g.GET("/plan_replayer/list", service.listFileGinHandler)
	g.GET("/plan_replayer/files", service.downloadGinHandler)
}

func NewPlanReplayerService(env string, stores storage.StorageFactory) *Service {
	return &Service{s: &file_download.Service{Query: file_download.NewStorageImpl(env, "plan_replayer", stores)}}
}

type Service struct {
	s *file_download.Service
}

// @Summary		List file info for plan replayer
// @Tags			plan replayer
// @Description	list file info for plan replayer
// @Produce		json
// @Param			X-Provider		header		string	true	"provider aws/gcp"
// @Param			X-Region		header		string	true	"region"
// @Param			X-Org-Id		header		string	true	"organization id from dbaas"
// @Param			X-Project-Id	header		string	true	"project id from dbaas"
// @Param			X-Cluster-Id	header		string	true	"cluster id from dbaas"
// @Param			instances		query		string	false	"instances, separate by comma"
// @Param			start			query		string	true	"start time in unix seconds"
// @Param			end				query		string	true	"end time in unix seconds"
// @Success		200				{object}	api.ListData
// @Router			/plan_replayer/list [get]
func (s *Service) listFileGinHandler(c *gin.Context) {
	s.s.ListFileGinHandler(c)
}

// @Summary		Download file for plan replayer
// @Tags			plan replayer
// @Description	download file for plan replayer
// @Produce		json
// @Param			provider	query	string	true	"provider aws/gcp"
// @Param			region		query	string	true	"region"
// @Param			key			query	string	true	"object key"
// @Success		200			{file}	file
// @Router			/plan_replayer/files [get]
func (s *Service) downloadGinHandler(c *gin.Context) {
	s.s.DownloadGinHandler(c)
}
