import { Entity, ItemStack } from "@minecraft/server";
import { randomChance } from "../../utils/systemHelper";
import { CustomItemTags } from "../utils/itemTags";

export const INFERNAL_NECKLACE = {
    _itemIdSuffix: "infernal_necklace",
    _burnChance: 0.25,
    _burnDuration: 6,
    _useEffects: true,

    /**
     * 
     * @param {ItemStack} itemStack 
     * @returns 
     */
    isInfernalNecklace: function(itemStack) {
        if (!itemStack) return
        
        const isCustom = CustomItemTags.isCustom(itemStack)
        const isInfernalNecklace = itemStack.typeId.endsWith(this._itemIdSuffix)

        return isCustom && isInfernalNecklace
    },

    /**
     * 
     * @param {Entity} entity 
     */
    applyAttackEffect: function(entity) {
        if (!randomChance(this._burnChance)) return;

        entity.setOnFire(this._burnDuration, this._useEffects)
    }
}