package repository

import (
	"testing"

	"go.mongodb.org/mongo-driver/bson"
)

func TestClearForPlacementScanFilter_ScopedTopic(t *testing.T) {
	filter := placementWriteFilter("tenant-1", "user-1", "brand-1", "topic-a")
	if filter["topic_id"] != "topic-a" {
		t.Fatalf("expected topic_id topic-a, got %v", filter["topic_id"])
	}
	if filter["tenant_id"] != "tenant-1" || filter["owner_uid"] != "user-1" {
		t.Fatalf("unexpected actor filter: %v", filter)
	}
	if _, ok := filter["brand_id"]; ok {
		t.Fatalf("topic-scoped filter must not include brand_id: %v", filter)
	}
}

func TestUntaggedTopicFilter_OnlyMissingTopicID(t *testing.T) {
	legacy := untaggedTopicFilter()
	orClause, ok := legacy["$or"].([]bson.M)
	if !ok || len(orClause) != 2 {
		t.Fatalf("expected two untagged topic clauses, got %v", legacy)
	}
}
