package services

import (
	"git.linuxforward.com/byop/byop-engine/clients"
	"git.linuxforward.com/byop/byop-engine/cloud"
	"git.linuxforward.com/byop/byop-engine/config"
	"git.linuxforward.com/byop/byop-engine/dbstore"
	"github.com/sirupsen/logrus"
)

// NewPreviewService creates the appropriate preview service based on configuration
// This is a factory function that replaces the manager pattern
func NewPreviewService(store *dbstore.SQLiteStore, ovhProvider cloud.Provider, cfg *config.Config, registryClient clients.RegistryClient, registryURL, registryUser, registryPass string) PreviewService {
	entry := logrus.WithField("service", "PreviewServiceFactory")

	// Determine which service to use based on configuration
	useLocal := cfg.LocalPreview

	// In debug/development mode, we could force local preview
	if cfg.Debug {
		entry.Info("Debug mode enabled - forcing local preview service")
		useLocal = true
	}

	if useLocal {
		entry.Warn("Using local preview service - this is for development/testing only, not recommended for production")
		return NewLocalPreviewService(store, cfg, registryClient, registryURL, registryUser, registryPass)
	}

	entry.Info("Using remote VPS preview service for production deployment")
	return NewRemotePreviewService(store, ovhProvider, cfg, registryClient, registryURL, registryUser, registryPass)
}
