package dev.lions.unionflow.server.repository;

import dev.lions.unionflow.server.entity.Message;
import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;
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
@DisplayName("MessageRepository")
class MessageRepositoryTest {

    @Inject
    MessageRepository messageRepository;

    @Test
    @TestTransaction
    @DisplayName("findMessageById retourne empty pour UUID inexistant")
    void findMessageById_inexistant_returnsEmpty() {
        Optional<Message> opt = messageRepository.findMessageById(UUID.randomUUID());
        assertThat(opt).isEmpty();
    }

    @Test
    @TestTransaction
    @DisplayName("findByConversationPagine retourne liste vide pour conversation inexistante")
    void findByConversationPagine_returnsEmpty() {
        List<Message> list = messageRepository.findByConversationPagine(UUID.randomUUID(), 0, 20);
        assertThat(list).isNotNull().isEmpty();
    }

    @Test
    @TestTransaction
    @DisplayName("countNonLus retourne >= 0 pour conversation inexistante")
    void countNonLus_returnsNonNegative() {
        long count = messageRepository.countNonLus(UUID.randomUUID(), UUID.randomUUID());
        assertThat(count).isGreaterThanOrEqualTo(0);
    }

    @Test
    @TestTransaction
    @DisplayName("findActifsByConversation retourne liste vide pour conversation inexistante")
    void findActifsByConversation_returnsEmpty() {
        List<Message> list = messageRepository.findActifsByConversation(UUID.randomUUID());
        assertThat(list).isNotNull().isEmpty();
    }

    @Test
    @TestTransaction
    @DisplayName("findDernierMessage retourne empty pour conversation inexistante")
    void findDernierMessage_returnsEmpty() {
        Optional<Message> opt = messageRepository.findDernierMessage(UUID.randomUUID());
        assertThat(opt).isEmpty();
    }

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