package source

import (
	"context"
	"io"

	"github.com/tidbcloud/observability/backup-worker/pkg/configs"
	"github.com/tidbcloud/observability/backup-worker/pkg/source/vm"
)

// Sourcer defines the contract for backup data sources.
//
// The interface is intentionally minimal - it returns an io.ReadCloser
// rather than structured data to:
// - Allow streaming large responses without buffering
// - Let the caller handle the raw data format
// - Support different export formats (native, JSON, CSV) via configuration
type Sourcer interface {
	// Pull retrieves time-series data for the specified time range.
	// The returned ReadCloser must be closed by the caller to prevent resource leaks.
	Pull(ctx context.Context, start, end int64) (io.ReadCloser, error)
}

// New creates a Sourcer based on the configuration.
//
// Currently only VictoriaMetrics is supported, but the factory pattern
// allows adding new sources without modifying the controller.
func New(_ context.Context, cfg configs.Config) Sourcer {
	return vm.New(cfg.Sources.VictoriaMetrics, cfg.RetryPolicy)
}
