package tidbtools

import (
	"github.com/gin-gonic/gin"
	toolsdto "github.com/tidbcloud/devops/api/tidbtools"
	ctrl "github.com/tidbcloud/devops/pkg/controller"
	ccsvcapi "github.com/tidbcloud/devops/pkg/service/cloudconfig/api"
)

// ListChangefeeds
//
//	@Id				TidbToolsControllerListChangefeeds
//	@Description	list internal changefeeds of a cluster
//	@Tags			TidbToolsController
//	@Accept			json
//	@Produce		json
//	@Param			cluster_id	path		string	true	"cluster id"
//	@Success		200			{object}	tidbtools.ListChangefeedsResp
//	@Failure		default		{object}	api.BaseResp
//	@Router			/api/v1/devops/{cluster_id}/tidbtools/changefeeds [get]
func (c *TidbToolsController) ListChangefeeds(ctx *gin.Context) {
	clusterID, ci, ok := c.requireClusterAccess(ctx)
	if !ok {
		return
	}
	resp, err := c.cloudConfig.ListInternalChangefeeds(ctx, ccsvcapi.ListInternalChangefeedsParam{
		TiDBClusterID: clusterID,
		ClusterType:   string(ci.clusterType),
	})
	if err != nil {
		ctrl.Fail(ctx, err)
		return
	}
	ctrl.Success(ctx, toolsdto.ToListChangefeedsResp(resp))
}
