/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.util;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.util.lang.Tuple;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public enum ColorContent implements StringRepresentable {
    WHITE("white"),
    ORANGE("orange"),
    MAGENTA("magenta"),
    LIGHT_BLUE("light_blue"),
    YELLOW("yellow"),
    LIME("lime"),
    PINK("pink"),
    GRAY("gray"),
    LIGHT_GRAY("light_gray"),
    CYAN("cyan"),
    PURPLE("purple"),
    BLUE("blue"),
    BROWN("brown"),
    GREEN("green"),
    RED("red"),
    BLACK("black");
    public final static Map<ColorContent, Tuple> COLOR_LANG_MAP =  Map.ofEntries(
            Map.entry(WHITE, Tuple.of("White", "白色", "白色", "白")),
            Map.entry(ORANGE, Tuple.of("Orange", "橙色", "橙色", "橙")),
            Map.entry(MAGENTA, Tuple.of("Magenta", "品红色", "洋紅色", "紫紅")),
            Map.entry(LIGHT_BLUE, Tuple.of("Light Blue", "淡蓝色", "淡藍色", "淺藍")),
            Map.entry(YELLOW, Tuple.of("Yellow", "黄色", "黃色", "黃")),
            Map.entry(LIME, Tuple.of("Lime", "黄绿色", "萊姆色", "青檸")),
            Map.entry(PINK, Tuple.of("Pink", "粉红色", "粉紅色", "粉紅")),
            Map.entry(GRAY, Tuple.of("Gray", "灰色", "灰色", "灰")),
            Map.entry(LIGHT_GRAY, Tuple.of("Light Gray", "淡灰色", "淡灰色", "淺灰")),
            Map.entry(CYAN, Tuple.of("Cyan", "青色", "青色", "青")),
            Map.entry(PURPLE, Tuple.of("Purple", "紫色", "紫色", "紫")),
            Map.entry(BLUE, Tuple.of("Blue", "蓝色", "藍色", "藍")),
            Map.entry(BROWN, Tuple.of("Brown", "棕色", "棕色", "棕")),
            Map.entry(GREEN, Tuple.of("Green", "绿色", "綠色", "綠")),
            Map.entry(RED, Tuple.of("Red", "红色", "紅色", "紅")),
            Map.entry(BLACK, Tuple.of("Black", "黑色", "黑色", "黑"))
    );

    public final static Map<ColorContent, Item> COLOR_DYE_ITEM_MAP = Map.ofEntries(
            Map.entry(WHITE,        Items.WHITE_DYE),
            Map.entry(ORANGE,       Items.ORANGE_DYE),
            Map.entry(MAGENTA,      Items.MAGENTA_DYE),
            Map.entry(LIGHT_BLUE,   Items.LIGHT_BLUE_DYE),
            Map.entry(YELLOW,       Items.YELLOW_DYE),
            Map.entry(LIME,         Items.LIME_DYE),
            Map.entry(PINK,         Items.PINK_DYE),
            Map.entry(GRAY,         Items.GRAY_DYE),
            Map.entry(LIGHT_GRAY,   Items.LIGHT_GRAY_DYE),
            Map.entry(CYAN,         Items.CYAN_DYE),
            Map.entry(PURPLE,       Items.PURPLE_DYE),
            Map.entry(BLUE,         Items.BLUE_DYE),
            Map.entry(BROWN,        Items.BROWN_DYE),
            Map.entry(GREEN,        Items.GREEN_DYE),
            Map.entry(RED,          Items.RED_DYE),
            Map.entry(BLACK,        Items.BLACK_DYE)
    );

    public final static Map<ColorContent, Item> COLOR_WOOL_ITEM_MAP = Map.ofEntries(
            Map.entry(WHITE,        Items.WHITE_WOOL),
            Map.entry(ORANGE,       Items.ORANGE_WOOL),
            Map.entry(MAGENTA,      Items.MAGENTA_WOOL),
            Map.entry(LIGHT_BLUE,   Items.LIGHT_BLUE_WOOL),
            Map.entry(YELLOW,       Items.YELLOW_WOOL),
            Map.entry(LIME,         Items.LIME_WOOL),
            Map.entry(PINK,         Items.PINK_WOOL),
            Map.entry(GRAY,         Items.GRAY_WOOL),
            Map.entry(LIGHT_GRAY,   Items.LIGHT_GRAY_WOOL),
            Map.entry(CYAN,         Items.CYAN_WOOL),
            Map.entry(PURPLE,       Items.PURPLE_WOOL),
            Map.entry(BLUE,         Items.BLUE_WOOL),
            Map.entry(BROWN,        Items.BROWN_WOOL),
            Map.entry(GREEN,        Items.GREEN_WOOL),
            Map.entry(RED,          Items.RED_WOOL),
            Map.entry(BLACK,        Items.BLACK_WOOL)
    );

    public final static BiMap<ColorContent, DyeColor> COLOR_DYE_MAP = HashBiMap.create();

    private final String name;

    ColorContent(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    // 获取所有颜色名称的列表
    public static final List<String> COLORS = Arrays.stream(values())
            .map(ColorContent::getName)
            .collect(Collectors.toList());

    // 获取所有枚举值的列表
    public static final List<ColorContent> VALUES = List.of(values());

    // 通过名称获取枚举
    public static ColorContent byName(String name) {
        return Arrays.stream(values())
                .filter(color -> color.name.equals(name))
                .findFirst()
                .orElse(WHITE); // 默认返回白色
    }

    @Override
    public @NotNull String getSerializedName() {
        return name;
    }

    @Contract(pure = true)
    @Override
    public @NotNull String toString() {
        return getSerializedName();
    }

    public static Tuple getColorNameTranslation(ColorContent color) {
        return COLOR_LANG_MAP.get(color);
    }
    public static void init() {
        COLOR_DYE_MAP.put(WHITE,        DyeColor.WHITE);
        COLOR_DYE_MAP.put(ORANGE,       DyeColor.ORANGE);
        COLOR_DYE_MAP.put(MAGENTA,      DyeColor.MAGENTA);
        COLOR_DYE_MAP.put(LIGHT_BLUE,   DyeColor.LIGHT_BLUE);
        COLOR_DYE_MAP.put(YELLOW,       DyeColor.YELLOW);
        COLOR_DYE_MAP.put(LIME,         DyeColor.LIME);
        COLOR_DYE_MAP.put(PINK,         DyeColor.PINK);
        COLOR_DYE_MAP.put(GRAY,         DyeColor.GRAY);
        COLOR_DYE_MAP.put(LIGHT_GRAY,   DyeColor.LIGHT_GRAY);
        COLOR_DYE_MAP.put(CYAN,         DyeColor.CYAN);
        COLOR_DYE_MAP.put(PURPLE,       DyeColor.PURPLE);
        COLOR_DYE_MAP.put(BLUE,         DyeColor.BLUE);
        COLOR_DYE_MAP.put(BROWN,        DyeColor.BROWN);
        COLOR_DYE_MAP.put(GREEN,        DyeColor.GREEN);
        COLOR_DYE_MAP.put(RED,          DyeColor.RED);
        COLOR_DYE_MAP.put(BLACK,        DyeColor.BLACK);
    }
    static {
        init();
    }
}
