package task

import (
	"context"
	"time"

	"github.com/go-logr/logr"
	"github.com/tidbcloud/infra-provider/pkg/deploy"
	"github.com/tidbcloud/infra-provider/regional-server/api/v1alpha1"
	"github.com/tidbcloud/infra-provider/regional-server/pkg/common/o11ycli"
	"github.com/tidbcloud/infra-provider/regional-server/pkg/config"
	"k8s.io/apimachinery/pkg/runtime"
	"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
	Finalizer = "o11yroute.dedicated.regionserver.tidbcloud.com/finalizer"
)

type Context struct {
	Scheme     *runtime.Scheme
	Local      client.Client
	Logger     logr.Logger
	VPC        *v1alpha1.VPC
	APPBox     *v1alpha1.APPBox
	APPRoute   *v1alpha1.APPRoute
	O11yRoute  *v1alpha1.O11yRoute
	Config     config.RootConfig // config is useless in this context
	O11yClient o11ycli.Interface
	BeginAt    *time.Time
}

var _ deploy.Task = &BaseTask{}

type BaseTask struct {
	*Context
}

func (t *BaseTask) Name() string {
	return ""
}

func (t *BaseTask) Category() deploy.TaskCategory {
	return deploy.NetworkTask
}

func (t *BaseTask) Create(ctx context.Context) deploy.Result {
	return deploy.Done()
}

func (t *BaseTask) PostCreate(ctx context.Context) deploy.Result {
	return deploy.Done()
}

func (t *BaseTask) Delete(ctx context.Context) deploy.Result {
	return deploy.Done()
}

func (t *BaseTask) PostDelete(ctx context.Context) deploy.Result {
	return deploy.Done()
}

func (t *BaseTask) MetricsStartTime() *time.Time {
	return t.BeginAt
}
