package shadowpool

import (
	"context"

	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/repository"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/service/serverless/cluster"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/pkg/config"
)

// Worker defines the interface for shadow pool workers.
type Worker interface {
	Fulfil(ctx context.Context) error
	Free(ctx context.Context) error
	Inventory(ctx context.Context) error
}

type worker struct {
	clusterRepo        repository.ClusterRepository
	poolRepo           repository.ShadowPoolRepository
	zeroRentRecordRepo repository.ZeroRentRecordRepository

	serverlessClusterSvc cluster.Service
	config               *config.ShadowPoolConfig
}

// NewWorker creates a new shadow pool worker instance.
func NewWorker(
	clusterRepo repository.ClusterRepository,
	poolRepo repository.ShadowPoolRepository,
	zeroRentRecordRepo repository.ZeroRentRecordRepository,
	serverlessClusterSvc cluster.Service,
	cfg *config.ShadowPoolConfig,
) Worker {
	return &worker{
		clusterRepo:          clusterRepo,
		poolRepo:             poolRepo,
		zeroRentRecordRepo:   zeroRentRecordRepo,
		serverlessClusterSvc: serverlessClusterSvc,
		config:               cfg,
	}
}
