package at.procon.dip.embedding.web;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import at.procon.dip.domain.document.DocumentType;
import at.procon.dip.domain.document.RepresentationType;
import at.procon.dip.embedding.service.ScopedEmbeddingEnqueueResult;
import at.procon.dip.embedding.service.ScopedEmbeddingEnqueueService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class EmbeddingAdminControllerTest {

    @Mock
    private ScopedEmbeddingEnqueueService enqueueService;

    private EmbeddingAdminController controller;

    @BeforeEach
    void setUp() {
        controller = new EmbeddingAdminController(enqueueService);
    }

    @Test
    void acceptsLowercaseDocumentTypeAndRepresentationType() {
        when(enqueueService.enqueueByDocumentType(
                org.mockito.ArgumentMatchers.any(),
                org.mockito.ArgumentMatchers.any(),
                org.mockito.ArgumentMatchers.any(),
                org.mockito.ArgumentMatchers.anyBoolean(),
                org.mockito.ArgumentMatchers.any(),
                org.mockito.ArgumentMatchers.anyBoolean(),
                org.mockito.ArgumentMatchers.anyInt()))
                .thenReturn(new ScopedEmbeddingEnqueueResult(
                        DocumentType.TED_NOTICE_LOT,
                        RepresentationType.SEMANTIC_TEXT,
                        null,
                        true,
                        "e5-default",
                        false,
                        1000,
                        0,
                        0
                ));

        controller.enqueueByDocumentType("ted_notice_lot", "semantic-text", null, true, null, false, 1000);

        ArgumentCaptor<DocumentType> documentType = ArgumentCaptor.forClass(DocumentType.class);
        ArgumentCaptor<RepresentationType> representationType = ArgumentCaptor.forClass(RepresentationType.class);
        verify(enqueueService).enqueueByDocumentType(
                documentType.capture(),
                representationType.capture(),
                org.mockito.ArgumentMatchers.isNull(),
                org.mockito.ArgumentMatchers.eq(true),
                org.mockito.ArgumentMatchers.isNull(),
                org.mockito.ArgumentMatchers.eq(false),
                org.mockito.ArgumentMatchers.eq(1000)
        );
        assertThat(documentType.getValue()).isEqualTo(DocumentType.TED_NOTICE_LOT);
        assertThat(representationType.getValue()).isEqualTo(RepresentationType.SEMANTIC_TEXT);
    }
}
