package mock

import (
	"context"
	"fmt"

	"github.com/pfeifferj/container-mom-go/pkg/operator/mongodb"
	"go.mongodb.org/mongo-driver/mongo"
)

// MockMongoDB implements the MongoDB interface for testing
type MockMongoDB struct {
	deployments map[string]mongodb.MongoDeployment
}

// NewMockMongoDB creates a new mock MongoDB client
func NewMockMongoDB() *MockMongoDB {
	return &MockMongoDB{
		deployments: make(map[string]mongodb.MongoDeployment),
	}
}

func (m *MockMongoDB) GetDeployment(ctx context.Context, id string) (*mongodb.MongoDeployment, error) {
	if deployment, ok := m.deployments[id]; ok {
		return &deployment, nil
	}
	return nil, fmt.Errorf("deployment not found")
}

func (m *MockMongoDB) ListDeployments(ctx context.Context) ([]mongodb.MongoDeployment, error) {
	deployments := make([]mongodb.MongoDeployment, 0, len(m.deployments))
	for _, d := range m.deployments {
		deployments = append(deployments, d)
	}
	return deployments, nil
}

func (m *MockMongoDB) CreateDeployment(ctx context.Context, deployment *mongodb.MongoDeployment) error {
	m.deployments[deployment.ID] = *deployment
	return nil
}

func (m *MockMongoDB) UpdateDeployment(ctx context.Context, deployment *mongodb.MongoDeployment) error {
	if _, ok := m.deployments[deployment.ID]; !ok {
		return fmt.Errorf("deployment not found")
	}
	m.deployments[deployment.ID] = *deployment
	return nil
}

func (m *MockMongoDB) DeleteDeployment(ctx context.Context, id string) error {
	delete(m.deployments, id)
	return nil
}

func (m *MockMongoDB) GetClient() *mongo.Client {
	return nil // Mock doesn't need a real client
}

func (m *MockMongoDB) Disconnect(ctx context.Context) error {
	return nil // Nothing to disconnect in mock
}

func (m *MockMongoDB) Database(name string) *mongo.Database {
	return nil // Mock doesn't need real database access
}
