package search

import (
	"context"
	"testing"
	"tercul/internal/domain"
	domainsearch "tercul/internal/domain/search"
	"github.com/stretchr/testify/assert"
)

func TestWeaviateWrapper_Search(t *testing.T) {
	mockWrapper := new(MockWeaviateWrapper)
	expectedResults := &domainsearch.SearchResults{
		Results: []domainsearch.SearchResultItem{
			{
				Type: "Work",
				Entity: domain.Work{
					Title: "Work 1",
					Description: "alpha beta",
					TranslatableModel: domain.TranslatableModel{Language: "en"},
				},
				Score: 0.95,
			},
		},
		TotalResults: 1,
		Limit:        1,
		Offset:      0,
	}
	params := domainsearch.SearchParams{
		Query: "alpha",
		Mode:  domainsearch.SearchModeHybrid,
		Filters: domainsearch.SearchFilters{
			Languages: []string{"en"},
		},
		Limit:  1,
		Offset: 0,
	}

	mockWrapper.On("Search", context.Background(), params).Return(expectedResults, nil)

	results, err := mockWrapper.Search(context.Background(), params)

	assert.NoError(t, err)
	assert.NotNil(t, results)
	assert.Equal(t, 1, len(results.Results))
	assert.Equal(t, "Work", results.Results[0].Type)
	work := results.Results[0].Entity.(domain.Work)
	assert.Equal(t, "Work 1", work.Title)

	mockWrapper.AssertExpectations(t)
}
