/*
 * Copyright (c) 2026 盐灯水母
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

package com.remains_cave.config;

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

public class RemainsCaveConfig {
    public static final ModConfigSpec COMMON_SPEC;
    public static final RemainsCaveConfig COMMON;

    static {
        Pair<RemainsCaveConfig, ModConfigSpec> pair = new ModConfigSpec.Builder().configure(RemainsCaveConfig::new);
        COMMON = pair.getLeft();
        COMMON_SPEC = pair.getRight();
    }

    // ========== 骷髅王配置（已有） ==========
    public final ModConfigSpec.DoubleValue maxHealth;
    public final ModConfigSpec.DoubleValue armor;
    public final ModConfigSpec.DoubleValue armortoughness;
    public final ModConfigSpec.DoubleValue attackDamage;
    public final ModConfigSpec.DoubleValue movementSpeed;
    public final ModConfigSpec.DoubleValue knockbackResistance;
    public final ModConfigSpec.DoubleValue followRange;
    public final ModConfigSpec.DoubleValue kingSmiteResistance;
    public final ModConfigSpec.DoubleValue enragelifestealMultiplier;

    public final ModConfigSpec.IntValue attackCooldown;
    public final ModConfigSpec.IntValue dashCooldown;
    public final ModConfigSpec.IntValue summonCooldown;

    public final ModConfigSpec.DoubleValue dashDamage;
    public final ModConfigSpec.IntValue dashWindupTicks;
    public final ModConfigSpec.IntValue dashTicks;
    public final ModConfigSpec.IntValue dashRecoveryTicks;
    public final ModConfigSpec.DoubleValue dashSpeed;

    public final ModConfigSpec.IntValue summonWantedCount;
    public final ModConfigSpec.IntValue summonWantedCountEnraged;
    public final ModConfigSpec.IntValue summonMaxCount;
    public final ModConfigSpec.IntValue summonMaxCountEnraged;
    public final ModConfigSpec.DoubleValue summonRadius;

    public final ModConfigSpec.DoubleValue lifestealMultiplier;
    public final ModConfigSpec.DoubleValue enrageThreshold;

    public final ModConfigSpec.DoubleValue warriorMaxHealth;
    public final ModConfigSpec.DoubleValue warriorArmor;
    public final ModConfigSpec.DoubleValue warriorAttackDamage;
    public final ModConfigSpec.DoubleValue warriorMovementSpeed;
    public final ModConfigSpec.DoubleValue warriorKnockbackResistance;
    public final ModConfigSpec.DoubleValue warriorFollowRange;
    public final ModConfigSpec.DoubleValue warriorSmiteResistance;
    public final ModConfigSpec.IntValue warriorAttackCooldown;   // 攻击间隔（ticks）
    public final ModConfigSpec.DoubleValue warriorArmorToughness;

    public final ModConfigSpec.DoubleValue archerMaxHealth;
    public final ModConfigSpec.DoubleValue archerArmor;
    public final ModConfigSpec.DoubleValue archerAttackDamage;
    public final ModConfigSpec.DoubleValue archerMovementSpeed;
    public final ModConfigSpec.DoubleValue archerFollowRange;
    public final ModConfigSpec.IntValue archerAttackCooldown;   // 攻击间隔（ticks）
    public final ModConfigSpec.DoubleValue archerArrowDamage;  // 新增：箭矢基础伤害
    public final ModConfigSpec.DoubleValue archerSmiteResistance;
    public final ModConfigSpec.DoubleValue archerArmorToughness;

    public final ModConfigSpec.DoubleValue warlockSmiteResistance;
    public final ModConfigSpec.DoubleValue warlockMaxHealth;
    public final ModConfigSpec.DoubleValue warlockMovementSpeed;
    public final ModConfigSpec.DoubleValue warlockArmor;
    public final ModConfigSpec.DoubleValue warlockAttackDamage;
    public final ModConfigSpec.DoubleValue warlockFollowRange;
    public final ModConfigSpec.IntValue warlockSpellCooldown;          // 共享冷却（tick）
    public final ModConfigSpec.IntValue warlockWindupTicks;            // 施法前摇（可选）
    public final ModConfigSpec.IntValue warlockRecoveryTicks;          // 施法后摇（可选）
    public final ModConfigSpec.IntValue warlockRuneInitialDelay;       // 法阵初始延迟（tick）
    public final ModConfigSpec.IntValue warlockRuneInterval;           // 法阵效果间隔（tick）
    public final ModConfigSpec.DoubleValue warlockRuneRadius;          // 法阵半径
    public final ModConfigSpec.DoubleValue warlockRuneDamage;          // 法阵伤害（每段）
    public final ModConfigSpec.DoubleValue warlockRuneHeal;            // 法阵治疗（每段）
    public final ModConfigSpec.IntValue warlockRuneBaseMaxEffects;     // 基础段数（无光环）
    public final ModConfigSpec.IntValue warlockRuneAuraExtraEffects;   // 有光环时增加的段数
    public final ModConfigSpec.DoubleValue warlockKinghealAmount;   // 有光环时增加的段数
    public final ModConfigSpec.DoubleValue warlockArmorToughness;


    public final ModConfigSpec.DoubleValue ARROW_BASE_DAMAGE;

    private RemainsCaveConfig(ModConfigSpec.Builder builder) {
        // ========== 骷髅王配置节 ==========
        builder.push("骷髅王 - 基础属性");
        maxHealth = builder.comment("骷髅王最大生命值").defineInRange("maxHealth", 200.0, 1.0, 10000.0);
        armor = builder.comment("护甲值").defineInRange("armor", 18.0, 0.0, 100.0);
        armortoughness = builder.comment("护甲韧性").defineInRange("armortoughness", 9.0, 0.0, 100.0);
        attackDamage = builder.comment("近战攻击力").defineInRange("attackDamage", 20.0, 0.0, 1000.0);
        movementSpeed = builder.comment("移动速度").defineInRange("movementSpeed", 0.25, 0.01, 1.0);
        knockbackResistance = builder.comment("击退抗性 (0-1)").defineInRange("knockbackResistance", 1.0, 0.0, 1.0);
        followRange = builder.comment("追击范围（格）").defineInRange("followRange", 32.0, 5.0, 100.0);
        kingSmiteResistance = builder.comment("骷髅王亡灵杀手抗性 (0~1)").defineInRange("kingSmiteResistance", 0.8, 0.0, 1.0);
        builder.pop();

        builder.push("骷髅王 - 技能冷却");
        attackCooldown = builder.comment("普通攻击冷却").defineInRange("attackCooldown", 30, 5, 200);
        dashCooldown = builder.comment("冲刺斩基础冷却").defineInRange("dashCooldown", 240, 10, 600);
        summonCooldown = builder.comment("召唤基础冷却").defineInRange("summonCooldown", 560, 20, 1200);
        builder.pop();

        builder.push("骷髅王 - 冲刺斩参数");
        dashDamage = builder.comment("冲刺斩伤害").defineInRange("dashDamage", 25.0, 1.0, 100.0);
        dashWindupTicks = builder.comment("冲刺前摇（tick）").defineInRange("dashWindupTicks", 5, 1, 40);
        dashTicks = builder.comment("冲刺持续时间（tick）").defineInRange("dashTicks", 3, 1, 40);
        dashRecoveryTicks = builder.comment("冲刺后摇（tick）").defineInRange("dashRecoveryTicks", 7, 1, 40);
        dashSpeed = builder.comment("冲刺速度（格/tick）").defineInRange("dashSpeed", 3.0, 0.5, 10.0);
        builder.pop();

        builder.push("骷髅王 - 召唤参数");
        summonWantedCount = builder.comment("非狂暴状态下每次召唤数量").defineInRange("summonWantedCount", 1, 0, 10);
        summonWantedCountEnraged = builder.comment("狂暴状态下每次召唤数量").defineInRange("summonWantedCountEnraged", 2, 0, 10);
        summonMaxCount = builder.comment("非狂暴状态最大召唤数量").defineInRange("summonMaxCount", 3, 0, 30);
        summonMaxCountEnraged = builder.comment("狂暴状态最大召唤数量").defineInRange("summonMaxCountEnraged", 5, 0, 30);
        summonRadius = builder.comment("召唤物生成半径").defineInRange("summonRadius", 3.0, 1.0, 10.0);
        builder.pop();

        builder.push("骷髅王 - 其他");
        lifestealMultiplier = builder.comment("吸血倍率（造成伤害的百分比，1.0=100%）").defineInRange("lifestealMultiplier", 1.0, 0.0, 10.0);
        enrageThreshold = builder.comment("狂暴血量阈值（百分比，0.5=50%）").defineInRange("enrageThreshold", 0.5, 0.0, 1.0);
        enragelifestealMultiplier = builder.comment("狂暴吸血倍率（造成伤害的百分比，1.0=100%）").defineInRange("enragelifestealMultiplier", 1.5, 0.0, 10.0);
        builder.pop();

        // ========== 骷髅战士配置节 ==========
        builder.push("骷髅战士 - 基础属性");
        warriorMaxHealth = builder.comment("生命值").defineInRange("warriorMaxHealth", 30.0, 1.0, 500.0);
        warriorArmor = builder.comment("护甲值").defineInRange("warriorArmor", 15.0, 0.0, 100.0);
        warriorArmorToughness = builder.comment("护甲韧性值").defineInRange("warriorArmorToughness", 15.0, 0.0, 100.0);
        warriorAttackDamage = builder.comment("近战攻击力").defineInRange("warriorAttackDamage", 10.0, 0.0, 100.0);
        warriorMovementSpeed = builder.comment("移动速度").defineInRange("warriorMovementSpeed", 0.33, 0.01, 1.0);
        warriorKnockbackResistance = builder.comment("击退抗性 (0-1)").defineInRange("warriorKnockbackResistance", 0.3, 0.0, 1.0);
        warriorFollowRange = builder.comment("追击范围（格）").defineInRange("warriorFollowRange", 25.0, 5.0, 100.0);
        warriorSmiteResistance = builder.comment("骷髅战士亡灵杀手抗性 (0~1)").defineInRange("warriorSmiteResistance", 0.55, 0.0, 1.0);
        builder.pop();

        builder.push("骷髅战士 - 攻击");
        warriorAttackCooldown = builder.comment("攻击间隔（tick，20ticks=1秒）").defineInRange("warriorAttackCooldown", 25, 5, 200);
        builder.pop();
        // ========== 骷髅弓手配置节 ==========
        builder.push("骷髅弓手 - 基础属性");
        archerMaxHealth = builder.comment("生命值").defineInRange("archerMaxHealth", 30.0, 1.0, 500.0);
        archerArmor = builder.comment("护甲值").defineInRange("archerArmor", 6.0, 0.0, 100.0);
        archerArmorToughness = builder.comment("护甲韧性值").defineInRange("archerArmorToughness", 3.0, 0.0, 100.0);
        archerAttackDamage = builder.comment("近战攻击力（实际伤害主要由箭矢决定，这条配置备用）").defineInRange("archerAttackDamage", 5.0, 0.0, 100.0);
        archerArrowDamage = builder.comment("箭矢基础伤害（实际伤害为两倍左右）").defineInRange("archerArrowDamage", 8.0, 0.1, 100.0);
        archerMovementSpeed = builder.comment("移动速度").defineInRange("archerMovementSpeed", 0.35, 0.01, 1.0);
        archerFollowRange = builder.comment("追击范围（格）").defineInRange("archerFollowRange", 25.0, 5.0, 100.0);
        archerSmiteResistance = builder.comment("骷髅弓手亡灵杀手抗性 (0~1)").defineInRange("archerSmiteResistance", 0.55, 0.0, 1.0);
        builder.pop();

        builder.push("骷髅弓手 - 攻击");
        archerAttackCooldown = builder.comment("攻击间隔（tick，20ticks=1秒）").defineInRange("archerAttackCooldown", 30, 5, 200);
        builder.pop();
        // ========== 骷髅术士配置节 ==========
        builder.push("骷髅术士 - 基础属性");
        warlockMaxHealth = builder.comment("生命值").defineInRange("warlockMaxHealth", 30.0, 1.0, 500.0);
        warlockMovementSpeed = builder.comment("移动速度").defineInRange("warlockMovementSpeed", 0.25, 0.01, 1.0);
        warlockArmor = builder.comment("护甲值").defineInRange("warlockArmor", 6.0, 0.0, 100.0);
        warlockArmorToughness = builder.comment("护甲韧性值").defineInRange("warlockArmorToughness", 3.0, 0.0, 100.0);
        warlockAttackDamage = builder.comment("近战攻击力（实际伤害由法阵决定）").defineInRange("warlockAttackDamage", 3.0, 0.0, 100.0);
        warlockFollowRange = builder.comment("追击范围（格）").defineInRange("warlockFollowRange", 20.0, 5.0, 100.0);
        warlockSmiteResistance = builder.comment("骷髅战士术士杀手抗性 (0~1)").defineInRange("warlockSmiteResistance", 0.55, 0.0, 1.0);
        builder.pop();

        builder.push("骷髅术士 - 技能参数");
        warlockSpellCooldown = builder.comment("施法冷却（tick，20ticks=1秒）").defineInRange("warlockSpellCooldown", 50, 10, 600);
        warlockWindupTicks = builder.comment("施法前摇（tick）").defineInRange("warlockWindupTicks", 6, 1, 40);
        warlockRecoveryTicks = builder.comment("施法后摇（tick）").defineInRange("warlockRecoveryTicks", 10, 1, 40);
        builder.pop();

        builder.push("骷髅术士 - 法阵参数");
        warlockRuneInitialDelay = builder.comment("法阵生成后首次生效延迟（tick）").defineInRange("warlockRuneInitialDelay", 10, 0, 100);
        warlockRuneInterval = builder.comment("法阵每段效果间隔（tick）").defineInRange("warlockRuneInterval", 10, 1, 100);
        warlockRuneRadius = builder.comment("法阵作用半径（格）").defineInRange("warlockRuneRadius", 1.5, 0.5, 10.0);
        warlockRuneDamage = builder.comment("每段对非骷髅造成的伤害").defineInRange("warlockRuneDamage", 4.0, 0.1, 100.0);
        warlockRuneHeal = builder.comment("每段对友方骷髅的治疗量").defineInRange("warlockRuneHeal", 2.0, 0.1, 100.0);
        warlockRuneBaseMaxEffects = builder.comment("基础段数（无光环）").defineInRange("warlockRuneBaseMaxEffects", 3, 1, 10);
        warlockRuneAuraExtraEffects = builder.comment("有光环时额外增加的段数").defineInRange("warlockRuneAuraExtraEffects", 2, 0, 10);
        warlockKinghealAmount = builder.comment("对骷髅王的治疗加成").defineInRange("warlockKinghealAmount", 1.5, 0, 5);
        builder.pop();

        builder.push("物品属性");
        ARROW_BASE_DAMAGE = builder.comment("箭矢基础伤害").defineInRange("arrowBaseDamage", 3, 0.1, 100.0);
        builder.pop();
    }
}