package dev.lions.unionflow.server.service;

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

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.security.TestSecurity;
import jakarta.inject.Inject;
import java.util.Map;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
 * Tests pour {@link KeycloakService#logSecurityInfo()} avec DEBUG désactivé.
 *
 * <p>Utilise un {@link QuarkusTestProfile} qui force le niveau de log sur INFO
 * pour {@code KeycloakService}, ce qui rend {@code LOG.isDebugEnabled()} = false.
 */
@QuarkusTest
@TestProfile(KeycloakServiceLogDebugDisabledTest.NoDebugProfile.class)
@DisplayName("KeycloakService.logSecurityInfo — branche LOG.isDebugEnabled() = false")
class KeycloakServiceLogDebugDisabledTest {

    /** Profil qui désactive DEBUG pour KeycloakService. */
    public static class NoDebugProfile implements QuarkusTestProfile {
        @Override
        public Map<String, String> getConfigOverrides() {
            return Map.of(
                "quarkus.log.category.\"dev.lions.unionflow.server.service.KeycloakService\".level", "INFO"
            );
        }
    }

    @Inject
    KeycloakService keycloakService;

    @Test
    @DisplayName("logSecurityInfo sans DEBUG → ne lève pas d'exception")
    void logSecurityInfo_debugDisabled_doesNotThrow() {
        keycloakService.logSecurityInfo();
    }

    @Test
    @TestSecurity(user = "admin@test.com", roles = {"ADMIN"})
    @DisplayName("logSecurityInfo authentifié sans DEBUG → ne lève pas d'exception")
    void logSecurityInfo_authenticatedDebugDisabled_doesNotThrow() {
        keycloakService.logSecurityInfo();
    }
}
