package dev.lions.user.manager.resource;

import dev.lions.user.manager.client.KeycloakAdminClient;
import io.quarkus.security.identity.SecurityIdentity;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
 * Tests supplémentaires pour RealmResource pour améliorer la couverture
 */
@ExtendWith(MockitoExtension.class)
class RealmResourceAdditionalTest {

    @Mock
    private KeycloakAdminClient keycloakAdminClient;

    @Mock
    private SecurityIdentity securityIdentity;

    @InjectMocks
    private RealmResource realmResource;

    @Test
    void testGetAllRealms_Success() {
        List<String> realms = Arrays.asList("master", "lions-user-manager", "test-realm");
        when(keycloakAdminClient.getAllRealms()).thenReturn(realms);

        List<String> result = realmResource.getAllRealms();

        assertNotNull(result);
        assertEquals(3, result.size());
    }

    @Test
    void testGetAllRealms_Empty() {
        when(keycloakAdminClient.getAllRealms()).thenReturn(List.of());

        List<String> result = realmResource.getAllRealms();

        assertNotNull(result);
        assertTrue(result.isEmpty());
    }

    @Test
    void testGetAllRealms_Exception() {
        when(keycloakAdminClient.getAllRealms()).thenThrow(new RuntimeException("Connection error"));

        assertThrows(RuntimeException.class, () -> realmResource.getAllRealms());
    }
}
