package repository

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"go.mongodb.org/mongo-driver/v2/bson"
)

func TestAccountBoundFilter_WithOrg(t *testing.T) {
	factory := NewAccountBoundFilter()
	accountRef := bson.NewObjectID()
	orgRef := bson.NewObjectID()

	query := factory.WithOrg(accountRef, orgRef)

	// Test that the query is not nil
	assert.NotNil(t, query)
}

func TestAccountBoundFilter_WithoutOrg(t *testing.T) {
	factory := NewAccountBoundFilter()
	accountRef := bson.NewObjectID()

	query := factory.WithoutOrg(accountRef)

	// Test that the query is not nil
	assert.NotNil(t, query)
}

func TestAccountBoundFilter_WithQuery(t *testing.T) {
	factory := NewAccountBoundFilter()
	accountRef := bson.NewObjectID()
	orgRef := bson.NewObjectID()
	additionalQuery := Query().Filter(Field("status"), "active")

	query := factory.WithQuery(accountRef, orgRef, additionalQuery)

	// Test that the query is not nil
	assert.NotNil(t, query)
}

func TestAccountBoundFilter_WithQueryNoOrg(t *testing.T) {
	factory := NewAccountBoundFilter()
	accountRef := bson.NewObjectID()
	additionalQuery := Query().Filter(Field("status"), "active")

	query := factory.WithQueryNoOrg(accountRef, additionalQuery)

	// Test that the query is not nil
	assert.NotNil(t, query)
}

func TestDefaultAccountBoundFilter(t *testing.T) {
	// Test that the default factory is not nil
	assert.NotNil(t, DefaultAccountBoundFilter)

	// Test that it's the correct type
	assert.IsType(t, &AccountBoundFilter{}, DefaultAccountBoundFilter)
}

func TestConvenienceFunctions(t *testing.T) {
	accountRef := bson.NewObjectID()
	orgRef := bson.NewObjectID()
	additionalQuery := Query().Filter(Field("status"), "active")

	// Test convenience functions
	query1 := WithOrg(accountRef, orgRef)
	assert.NotNil(t, query1)

	query2 := WithoutOrg(accountRef)
	assert.NotNil(t, query2)

	query3 := WithQuery(accountRef, orgRef, additionalQuery)
	assert.NotNil(t, query3)

	query4 := WithQueryNoOrg(accountRef, additionalQuery)
	assert.NotNil(t, query4)
}

func TestFilterFactoryConsistency(t *testing.T) {
	factory := NewAccountBoundFilter()
	accountRef := bson.NewObjectID()
	orgRef := bson.NewObjectID()

	// Test that factory methods and convenience functions produce the same result
	query1 := factory.WithOrg(accountRef, orgRef)
	query2 := WithOrg(accountRef, orgRef)

	// Both should be valid queries
	assert.NotNil(t, query1)
	assert.NotNil(t, query2)
}
