package testing

import (
	"context"
	"testing"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"k8s.io/client-go/kubernetes/scheme"
	"sigs.k8s.io/controller-runtime/pkg/client/fake"

	momv1 "github.com/pfeifferj/container-mom-go/pkg/apis/containermom/v1alpha1"
)

// NewTestOperator creates a new operator instance for testing
func NewTestOperator(t *testing.T) (*mongo.Client, error) {
	// Create test MongoDB client
	client, err := mongo.Connect(context.Background(), options.Client().ApplyURI("mongodb://localhost:27017"))
	if err != nil {
		t.Fatalf("Failed to connect to MongoDB: %v", err)
	}

	return client, nil
}

// NewFakeClient creates a new fake Kubernetes client for testing
func NewFakeClient() (client.Client, error) {
	// Register our API types
	s := scheme.Scheme
	if err := momv1.AddToScheme(s); err != nil {
		return nil, err
	}

	return fake.NewClientBuilder().WithScheme(s).Build(), nil
}
