import { Player, EntityEquippableComponent, EquipmentSlot } from "@minecraft/server"
import { EntityHelper as EHelper } from "../../entities/utils/entityHelper"

export const COBALTIUM_ARMOR = {
    _headArmorId: "piki_beyondsurvival:cobaltium_helmet",
    _chestArmorId: "piki_beyondsurvival:cobaltium_chestplate",
    _legsArmorId: "piki_beyondsurvival:cobaltium_leggings",
    _bootsArmorId: "piki_beyondsurvival:cobaltium_boots",

    _fullEquipEffect: EHelper.createEntityEffect("haste", 15, 0, true),

    /**
     * 
     * @param {EntityEquippableComponent} equippable 
     */
    isFullArmorEquipped(equippable) {
        const headArmorItem = equippable.getEquipment(EquipmentSlot.Head)
        const chestArmorItem = equippable.getEquipment(EquipmentSlot.Chest)
        const legsArmorItem = equippable.getEquipment(EquipmentSlot.Legs)
        const bootsArmorItem = equippable.getEquipment(EquipmentSlot.Feet)

        const headArmorItemId = headArmorItem?.typeId
        const chestArmorItemId = chestArmorItem?.typeId
        const legsArmorItemId = legsArmorItem?.typeId
        const bootsArmorItemId = bootsArmorItem?.typeId

        return (headArmorItemId == this._headArmorId  &&
                chestArmorItemId?.includes(this._chestArmorId) &&
                legsArmorItemId == this._legsArmorId &&
                bootsArmorItemId == this._bootsArmorId
        )
    },
    /**
     * 
     * @param {Player} player 
     */
    applyFullEquipEffect(player) {
        const {effectType, duration, amplifier, showParticles} = this._fullEquipEffect
        if (player.getEffect(effectType)) return
        player.addEffect(effectType, duration, {amplifier: amplifier, showParticles: showParticles})
    }
}