package dev.lions.unionflow.server.repository;

import dev.lions.unionflow.server.entity.ConversationParticipant;
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("ConversationParticipantRepository")
class ConversationParticipantRepositoryTest {

    @Inject
    ConversationParticipantRepository conversationParticipantRepository;

    @Test
    @TestTransaction
    @DisplayName("findParticipant retourne empty pour conversation inexistante")
    void findParticipant_returnsEmpty() {
        Optional<ConversationParticipant> opt =
            conversationParticipantRepository.findParticipant(UUID.randomUUID(), UUID.randomUUID());
        assertThat(opt).isEmpty();
    }

    @Test
    @TestTransaction
    @DisplayName("findByConversation retourne liste vide pour conversation inexistante")
    void findByConversation_returnsEmpty() {
        List<ConversationParticipant> list =
            conversationParticipantRepository.findByConversation(UUID.randomUUID());
        assertThat(list).isNotNull().isEmpty();
    }

    @Test
    @TestTransaction
    @DisplayName("estParticipant retourne false pour conversation inexistante")
    void estParticipant_returnsFalse() {
        boolean result = conversationParticipantRepository.estParticipant(
            UUID.randomUUID(), UUID.randomUUID());
        assertThat(result).isFalse();
    }

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

    @Test
    @TestTransaction
    @DisplayName("listAll retourne liste non nulle")
    void listAll_returnsNonNull() {
        assertThat(conversationParticipantRepository.listAll()).isNotNull();
    }
}
