package clientv2

import (
	"context"

	scalerpb "github.com/tidbcloud/aws-shared-provider/pkg/tidbworker/proto/scaler"
)

type autoAnalyzeClient interface {
	// RegisterAutoAnalyze notifies the manager that an auto-analyze task has been registered.
	RegisterAutoAnalyze(ctx context.Context, taskID uint64) error
	// RecycleAutoAnalyze notifies the manager that an auto-analyze task has been completed.
	RecycleAutoAnalyze(ctx context.Context, taskID uint64) error
}

var _ autoAnalyzeClient = &client{}

func (c *client) RegisterAutoAnalyze(ctx context.Context, taskID uint64) error {
	req := &scalerpb.RegisterAutoAnalyzeRequest{
		Header: requestHeader(c),
		TaskId: taskID,
	}
	resp, err := c.grpcClient.RegisterAutoAnalyze(ctx, req)
	return getError("RegisterAutoAnalyze", err, resp)
}

func (c *client) RecycleAutoAnalyze(ctx context.Context, taskID uint64) error {
	req := &scalerpb.RecycleAutoAnalyzeRequest{
		Header: requestHeader(c),
		TaskId: taskID,
	}
	resp, err := c.grpcClient.RecycleAutoAnalyze(ctx, req)
	return getError("RecycleAutoAnalyze", err, resp)
}
