package com.tiedup.remake.entities;

import com.tiedup.remake.core.SettingsAccessor;
import com.tiedup.remake.dialogue.SpeakerType;
import com.tiedup.remake.entities.skins.EliteKidnapperSkinManager;
import com.tiedup.remake.entities.skins.Gender;
import java.util.UUID;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.level.Level;

/**
 * Elite Kidnapper - Rare, faster, more dangerous kidnapper variant.
 *
 *
 * Differences from regular EntityKidnapper:
 * - Faster movement speed (0.35 vs 0.27)
 * - Higher health (40 vs 20)
 * - Faster capture time (10 ticks vs 20 ticks)
 * - Dark red name color
 * - Dedicated elite skins (Suki, Carol, Athena, Evelyn)
 * - Rarer spawns
 * - Higher item probabilities
 *
 * Refactored: Uses parent's variant system via virtual methods.
 */
public class EntityKidnapperElite extends EntityKidnapper {

    // CONSTANTS

    public static final double ELITE_MAX_HEALTH = 40.0D;
    public static final double ELITE_MOVEMENT_SPEED = 0.35D;
    public static final double ELITE_KNOCKBACK_RESISTANCE = 0.9D;
    public static final double ELITE_FOLLOW_RANGE = 60.0D;
    public static final double ELITE_ATTACK_DAMAGE = 8.0D;
    public static final int ELITE_CAPTURE_TIME_TICKS = 10;
    public static final int ELITE_NAME_COLOR = 0xAA0000;

    // CONSTRUCTOR

    public EntityKidnapperElite(
        EntityType<? extends EntityKidnapperElite> type,
        Level level
    ) {
        super(type, level);
    }

    // ATTRIBUTES

    /**
     * Create elite kidnapper attributes.
     * Faster and tougher than regular kidnappers.
     */
    public static AttributeSupplier.Builder createAttributes() {
        return Mob.createMobAttributes()
            .add(Attributes.MAX_HEALTH, ELITE_MAX_HEALTH)
            .add(Attributes.MOVEMENT_SPEED, ELITE_MOVEMENT_SPEED)
            .add(Attributes.KNOCKBACK_RESISTANCE, ELITE_KNOCKBACK_RESISTANCE)
            .add(Attributes.FOLLOW_RANGE, ELITE_FOLLOW_RANGE)
            .add(Attributes.ATTACK_DAMAGE, ELITE_ATTACK_DAMAGE);
    }

    // VARIANT SYSTEM - Override virtual methods

    @Override
    public KidnapperVariant lookupVariantById(String variantId) {
        return EliteKidnapperSkinManager.CORE.getVariant(variantId);
    }

    @Override
    public KidnapperVariant computeVariantForEntity(UUID entityUUID) {
        Gender preferredGender = SettingsAccessor.getPreferredSpawnGender(
            this.level() != null ? this.level().getGameRules() : null
        );
        return EliteKidnapperSkinManager.CORE.getVariantForEntity(
            entityUUID,
            preferredGender
        );
    }

    @Override
    public String getVariantTextureFolder() {
        return "textures/entity/kidnapper/elite/";
    }

    @Override
    public String getDefaultVariantId() {
        return "suki";
    }

    @Override
    public void applyVariantName(KidnapperVariant variant) {
        // Elite variants always use their default name
        this.setNpcName(variant.defaultName());
    }

    @Override
    public String getVariantNBTKey() {
        // Use different key for backward compatibility with existing saves
        return "EliteVariantName";
    }

    // CAPTURE TIMING (Faster for Elite)

    /**
     * Elite kidnappers tie up targets in half the time.
     */
    @Override
    public int getCaptureBindTime() {
        return ELITE_CAPTURE_TIME_TICKS;
    }

    /**
     * Elite kidnappers gag targets in half the time.
     */
    @Override
    public int getCaptureGagTime() {
        return ELITE_CAPTURE_TIME_TICKS;
    }

    // DISPLAY

    @Override
    public Component getDisplayName() {
        return Component.literal(this.getNpcName()).withStyle(
            Style.EMPTY.withColor(ELITE_NAME_COLOR)
        );
    }

    // OVERRIDES

    /**
     * Elite kidnappers use higher item probabilities.
     * - 100% bind (same as regular)
     * - 100% gag (instead of 50%)
     * - 80% mittens (instead of 40%)
     * - 60% earplugs (instead of 30%)
     * - 40% blindfold (instead of 20%)
     */
    @Override
    public KidnapperItemSelector.SelectionResult selectItemsForKidnapper() {
        return KidnapperItemSelector.selectForEliteKidnapper();
    }

    // DIALOGUE SPEAKER (Elite-specific)

    @Override
    public SpeakerType getSpeakerType() {
        return SpeakerType.KIDNAPPER_ELITE;
    }

    @Override
    public int getSpeakerMood() {
        // Elite kidnappers are always confident
        return 70;
    }
}
