package cron

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

	srvv1 "github.com/pingcap-inc/pchub/internal/apiserver/service/v1"
	"github.com/pingcap-inc/pchub/internal/apiserver/store"
	"github.com/pingcap-inc/pchub/pkg/log"
	"github.com/pingcap-inc/pchub/pkg/util/ginres"
)

type CronController struct {
	srv srvv1.Service
}

func NewCronController(store store.Factory) *CronController {
	return &CronController{
		srv: srvv1.NewService(store),
	}
}

func (c *CronController) StartSync(ctx *gin.Context) {
	log.L(ctx).Info("CronController.StartSync called.")

	funcName := ctx.Param("function")
	go c.srv.Cron().StartSync(ctx, funcName)
	ginres.WriteResponse(ctx, nil, "Start sync "+funcName)
}
