package com.firefrostgaming.rules;

import net.neoforged.neoforge.common.ModConfigSpec;
import org.apache.commons.lang3.StringUtils;

public class ServerRulesConfig {
    public static final ModConfigSpec SPEC;
    public static final ModConfigSpec.ConfigValue<String> BOT_TOKEN;
    public static final ModConfigSpec.ConfigValue<String> CHANNEL_ID;
    public static final ModConfigSpec.ConfigValue<String> MESSAGE_ID;
    public static final ModConfigSpec.IntValue COOLDOWN_SECONDS;
    public static final ModConfigSpec.IntValue CACHE_MINUTES;

    static {
        ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
        builder.comment("Firefrost 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("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}$");
    }
}
