package com.cameleer.server.core.admin;

import org.junit.jupiter.api.Test;

import java.util.List;

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

class SensitiveKeysMergerTest {

    @Test
    void bothNull_returnsNull() {
        assertNull(SensitiveKeysMerger.merge(null, null));
    }

    @Test
    void globalOnly_returnsGlobal() {
        List<String> result = SensitiveKeysMerger.merge(
                List.of("Authorization", "Cookie"), null);
        assertEquals(List.of("Authorization", "Cookie"), result);
    }

    @Test
    void perAppOnly_returnsPerApp() {
        List<String> result = SensitiveKeysMerger.merge(
                null, List.of("X-Internal-*"));
        assertEquals(List.of("X-Internal-*"), result);
    }

    @Test
    void union_mergesWithoutDuplicates() {
        List<String> result = SensitiveKeysMerger.merge(
                List.of("Authorization", "Cookie"),
                List.of("Cookie", "X-Custom"));
        assertEquals(List.of("Authorization", "Cookie", "X-Custom"), result);
    }

    @Test
    void caseInsensitiveDedup_preservesFirstCasing() {
        List<String> result = SensitiveKeysMerger.merge(
                List.of("Authorization"),
                List.of("authorization", "AUTHORIZATION"));
        assertEquals(List.of("Authorization"), result);
    }

    @Test
    void emptyGlobal_returnsEmptyList() {
        List<String> result = SensitiveKeysMerger.merge(List.of(), null);
        assertEquals(List.of(), result);
    }

    @Test
    void emptyGlobalWithPerApp_returnsPerApp() {
        List<String> result = SensitiveKeysMerger.merge(
                List.of(), List.of("X-Custom"));
        assertEquals(List.of("X-Custom"), result);
    }

    @Test
    void globPatterns_preserved() {
        List<String> result = SensitiveKeysMerger.merge(
                List.of("*password*", "*secret*"),
                List.of("X-Internal-*"));
        assertEquals(List.of("*password*", "*secret*", "X-Internal-*"), result);
    }
}
