package com.discordrules;

import net.minecraftforge.common.ForgeConfigSpec;
import org.apache.commons.lang3.StringUtils;

public class ServerRulesConfig {
    public static final ForgeConfigSpec SPEC;
    public static final ForgeConfigSpec.ConfigValue<String> BOT_TOKEN;
    public static final ForgeConfigSpec.ConfigValue<String> CHANNEL_ID;
    public static final ForgeConfigSpec.ConfigValue<String> MESSAGE_ID;
    public static final ForgeConfigSpec.IntValue COOLDOWN_SECONDS;
    public static final ForgeConfigSpec.IntValue CACHE_MINUTES;
    public static final ForgeConfigSpec.ConfigValue<String> HEADER_COLOR;
    public static final ForgeConfigSpec.ConfigValue<String> BODY_COLOR;
    public static final ForgeConfigSpec.BooleanValue STRIP_EMOJIS;

    static {
        ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
        builder.comment("Discord Rules Mod Configuration",
                "IMPORTANT: Do not remove [section] headers when editing.",
                "Values must stay under their section or the mod cannot read them.")
               .push("discord");
        BOT_TOKEN = builder.comment("Discord Bot Token").define("bot_token", "YOUR_TOKEN_HERE");
        CHANNEL_ID = builder.comment("Discord Channel ID").define("channel_id", "1234567890123456789");
        MESSAGE_ID = builder.comment("Discord Message ID").define("message_id", "1234567890123456789");
        builder.pop();
        builder.push("display");
        HEADER_COLOR = builder.comment("Header color (bold lines). Valid: BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE").define("header_color", "GOLD");
        BODY_COLOR = builder.comment("Body color (regular lines and bullet points)").define("body_color", "YELLOW");
        STRIP_EMOJIS = builder.comment("Strip emojis that Minecraft can't render (recommended: true)").define("strip_emojis", true);
        builder.pop();
        builder.push("performance");
        COOLDOWN_SECONDS = builder.comment("Per-player cooldown in seconds").defineInRange("cooldown_seconds", 60, 0, 3600);
        CACHE_MINUTES = builder.comment("Cache duration in minutes").defineInRange("cache_minutes", 30, 1, 1440);
        builder.pop();
        SPEC = builder.build();
    }

    public static boolean isMessageIdValid() {
        String id = MESSAGE_ID.get();
        return StringUtils.isNotBlank(id) && id.matches("^\\d{17,20}$");
    }
}
