package dev.lions.unionflow.server.repository;

import dev.lions.unionflow.server.entity.RolePermission;
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 RolePermissionRepositoryTest {

    @Inject
    RolePermissionRepository rolePermissionRepository;

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

    @Test
    @TestTransaction
    @DisplayName("findRolePermissionById retourne empty pour UUID inexistant")
    void findRolePermissionById_inexistant_returnsEmpty() {
        Optional<RolePermission> opt = rolePermissionRepository.findRolePermissionById(UUID.randomUUID());
        assertThat(opt).isEmpty();
    }

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

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

    @Test
    @TestTransaction
    @DisplayName("findByRoleId retourne une liste")
    void findByRoleId_returnsList() {
        List<RolePermission> list = rolePermissionRepository.findByRoleId(UUID.randomUUID());
        assertThat(list).isNotNull();
    }

    @Test
    @TestTransaction
    @DisplayName("findByPermissionId retourne une liste")
    void findByPermissionId_returnsList() {
        List<RolePermission> list = rolePermissionRepository.findByPermissionId(UUID.randomUUID());
        assertThat(list).isNotNull();
    }

    @Test
    @TestTransaction
    @DisplayName("findByRoleAndPermission retourne null pour des UUIDs inexistants")
    void findByRoleAndPermission_inexistant_returnsNull() {
        RolePermission result = rolePermissionRepository.findByRoleAndPermission(UUID.randomUUID(), UUID.randomUUID());
        assertThat(result).isNull();
    }
}
