/*
 * Copyright (c) 2026 GeyserMC. http://geysermc.org
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @author GeyserMC
 * @link https://github.com/GeyserMC/Geyser
 */

package org.geysermc.geyser.registry.mappings;


import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCustomSkullsEvent;
import org.junit.jupiter.api.Test;

import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

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

public class CustomSkullsLoaderTest {

    @Test
    void readMappings() throws URISyntaxException {
        Path skullConfigPath = getConfigResource("configuration/custom-skulls.json");
        Map<GeyserDefineCustomSkullsEvent.SkullTextureType, List<String>> map = new EnumMap<>(GeyserDefineCustomSkullsEvent.SkullTextureType.class);
        MappingsConfigReader.readCustomMappings(MappingsType.SKULLS, skullConfigPath, map::put);

        assertEquals("GeyserMC", map.get(GeyserDefineCustomSkullsEvent.SkullTextureType.USERNAME).getFirst());
        assertEquals("8b8d8e8f-2759-47c6-acb5-5827de8a72b8", map.get(GeyserDefineCustomSkullsEvent.SkullTextureType.UUID).getFirst());
        assertEquals("ewogICJ0aW1lc3RhbXAiIDogMTY1NzMyMjIzOTgzMywKICAicHJvZmlsZUlkIiA6ICJjZGRiZTUyMGQwNDM0YThiYTFjYzlmYzkyZmRlMmJjZiIsCiAgInByb2ZpbGVOYW1lIiA6ICJBbWJlcmljaHUiLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTkwNzkwYzU3ZTE4MWVkMTNhZGVkMTRjNDdlZTJmN2M4ZGUzNTMzZTAxN2JhOTU3YWY3YmRmOWRmMWJkZTk0ZiIsCiAgICAgICJtZXRhZGF0YSIgOiB7CiAgICAgICAgIm1vZGVsIiA6ICJzbGltIgogICAgICB9CiAgICB9CiAgfQp9", map.get(GeyserDefineCustomSkullsEvent.SkullTextureType.PROFILE).getFirst());
        assertEquals("a90790c57e181ed13aded14c47ee2f7c8de3533e017ba957af7bdf9df1bde94f", map.get(GeyserDefineCustomSkullsEvent.SkullTextureType.SKIN_HASH).getFirst());
    }

    private Path getConfigResource(String name) throws URISyntaxException {
        URL url = Objects.requireNonNull(getClass().getClassLoader().getResource(name), "No resource for name: " + name);
        return Path.of(url.toURI());
    }
}
