package mock

import (
	"context"
	"testing"

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

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

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

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

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

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

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

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

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

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