package mock

import (
	"context"
	"testing"

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

func TestMockMongoDBUtils(t *testing.T) {
	ctx := context.TODO()
	mock := NewMockMongoDB()

	// Set up expectations
	mockClient, _ := mongo.Connect(ctx)
	mock.On("GetClient").Return(mockClient)
	mock.On("Database", "test").Return(mockClient.Database("test"))
	mock.On("Disconnect", mock.Anything).Return(nil)
	mock.On("CreateDeployment", mock.Anything, mock.AnythingOfType("*api.MongoDeployment")).Return(nil)
	mock.On("GetDeployment", mock.Anything, "test-deployment").Return(&api.MongoDeployment{
		ID:   "test-deployment",
		Name: "test-deployment",
	}, nil)
	mock.On("UpdateDeployment", mock.Anything, mock.AnythingOfType("*api.MongoDeployment")).Return(nil)

	// Test GetClient
	client := mock.GetClient()
	assert.NotNil(t, client)

	// Test Database
	db := mock.Database("test")
	assert.NotNil(t, db)

	// Test Disconnect
	assert.NoError(t, mock.Disconnect(ctx))

	// Create test deployment
	deployment := &api.MongoDeployment{
		ID:   "test-deployment",
		Name: "test-deployment",
	}
	err := mock.CreateDeployment(ctx, deployment)
	assert.NoError(t, err)

	// Test UpdateDeployment
	err = mock.UpdateDeployment(ctx, deployment)
	assert.NoError(t, err)

	// Verify update
	updated, err := mock.GetDeployment(ctx, deployment.ID)
	assert.NoError(t, err)
	assert.Equal(t, deployment.ID, updated.ID)

	// Verify all expectations were met
	mock.AssertExpectations(t)
}
