package at.procon.dip.domain.document.web;

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

import at.procon.dip.domain.document.DocumentFamily;
import at.procon.dip.domain.document.DocumentStatus;
import at.procon.dip.domain.document.DocumentType;
import at.procon.dip.domain.document.dto.GenericDocumentDetailResponse;
import at.procon.dip.domain.document.service.GenericDocumentReadService;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class GenericDocumentControllerTest {

    @Mock private GenericDocumentReadService readService;
    private GenericDocumentController controller;

    @BeforeEach
    void setUp() {
        controller = new GenericDocumentController(readService);
    }

    @Test
    void shouldReturnDocumentWhenFound() {
        UUID id = UUID.randomUUID();
        when(readService.findById(id)).thenReturn(Optional.of(new GenericDocumentDetailResponse(
                id, null, null, DocumentType.TEXT, DocumentFamily.GENERIC, DocumentStatus.REPRESENTED,
                "Doc", null, null, "text/plain", "API:1", "hash", null, null, List.of(), List.of(), List.of()
        )));

        var response = controller.getDocument(id);
        assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
        assertThat(response.getBody()).isNotNull();
        assertThat(response.getBody().id()).isEqualTo(id);
    }
}
