package dev.lions.unionflow.server.repository;

import dev.lions.unionflow.server.api.enums.document.TypeDocument;
import dev.lions.unionflow.server.entity.Document;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.TestTransaction;
import jakarta.inject.Inject;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
class DocumentRepositoryTest {

    @Inject
    DocumentRepository documentRepository;

    @Test
    @TestTransaction
    @DisplayName("findById retourne null pour UUID inexistant")
    void findById_inexistant_returnsNull() {
        assertThat(documentRepository.findById(UUID.randomUUID())).isNull();
    }

    @Test
    @TestTransaction
    @DisplayName("findDocumentById retourne empty pour UUID inexistant")
    void findDocumentById_inexistant_returnsEmpty() {
        Optional<Document> opt = documentRepository.findDocumentById(UUID.randomUUID());
        assertThat(opt).isEmpty();
    }

    @Test
    @TestTransaction
    @DisplayName("findByHashMd5 retourne empty pour hash inexistant")
    void findByHashMd5_inexistant_returnsEmpty() {
        Optional<Document> opt = documentRepository.findByHashMd5("hash-" + UUID.randomUUID());
        assertThat(opt).isEmpty();
    }

    @Test
    @TestTransaction
    @DisplayName("listAll retourne une liste")
    void listAll_returnsList() {
        List<Document> list = documentRepository.listAll();
        assertThat(list).isNotNull();
    }

    @Test
    @TestTransaction
    @DisplayName("count retourne un nombre >= 0")
    void count_returnsNonNegative() {
        assertThat(documentRepository.count()).isGreaterThanOrEqualTo(0L);
    }

    @Test
    @TestTransaction
    @DisplayName("findByType retourne une liste")
    void findByType_returnsList() {
        List<Document> list = documentRepository.findByType(TypeDocument.FACTURE);
        assertThat(list).isNotNull();
    }

    @Test
    @TestTransaction
    @DisplayName("findAllActifs retourne une liste")
    void findAllActifs_returnsList() {
        List<Document> list = documentRepository.findAllActifs();
        assertThat(list).isNotNull();
    }

    @Test
    @TestTransaction
    @DisplayName("findByHashSha256 retourne empty pour hash inexistant")
    void findByHashSha256_inexistant_returnsEmpty() {
        java.util.Optional<Document> opt = documentRepository.findByHashSha256("sha256-" + UUID.randomUUID());
        assertThat(opt).isEmpty();
    }
}
