export class ArmorPiece {
    constructor(typeId, slot, effects = []) {
        this.typeId = typeId;
        this.slot = slot; // "Head", "Chest", "Legs", "Feet", etc.
        this.effects = effects; // Array de efectos para esta pieza de armadura
    }

    applyEffects(player) {
        this.effects.forEach(effect => {
            player.addEffect(effect.name, effect.duration, { amplifier: effect.amplifier, showParticles: false });
        });
    }
}

export class ArmorSet {
    constructor(setName, pieces = [], fullSetEffects = [], speed = 0.1) {
        this.setName = setName;
        this.pieces = pieces; // Array de ArmorPiece
        this.fullSetEffects = fullSetEffects; // Efectos aplicados solo cuando el set está completo
        this.speed = speed;
    }
    checkPieceEquipped(player, piece) {
        const equipment = player.getComponent("minecraft:equippable");
        if (!equipment) {
            return false;
        }
        const equippedPiece = equipment.getEquipment(piece.slot);

        if (!equippedPiece) {
            return false;
        }

        if (equippedPiece.typeId !== piece.typeId) {
            return false;
        }

        return true;
    }

    isFullSetEquipped(player) {

        for (const piece of this.pieces) {

            if (!this.checkPieceEquipped(player, piece)) {
                return false;
            }
        }

        return true;
    }

    applySetEffects(player) {

        try {

            const fullSetEquipped = this.isFullSetEquipped(player);
            if (fullSetEquipped) {
                this.fullSetEffects.forEach(effect => {
                    try {
                        player.addEffect(effect.name, effect.duration, { amplifier: effect.amplifier, showParticles: false });

                    } catch (effectError) {

                    }
                });
                this.modifySpeed(player, this.speed);
            }
        } catch (e) {
        }
    }
    modifySpeed(player, speed) {

        const movement = player.getComponent("minecraft:underwater_movement");
        movement.setCurrentValue(speed);
    }
    resetSpeed(player) {
        const movement = player.getComponent("minecraft:underwater_movement");
        movement.resetToDefaultValue();

    }
}
