// medicalEffects.js

import { world } from "@minecraft/server";

const ItemmedicalEffectsComponent = {
    onConsume({ itemStack, source }) {
        if (itemStack.typeId === "fw:rad_away") {
            // Removes 5 Rads
            source.runCommandAsync("scoreboard players remove @s Rads 5").catch(() => {});
        } else if (itemStack.typeId === "fw:overdrive") {
            source.addEffect("minecraft:strength", 1200, {
                amplifier: 1,
                showParticles: false,
            });
            source.addEffect("minecraft:hunger", 500, {
                amplifier: 0,
                showParticles: false,
            });
            source.addEffect("minecraft:haste", 500, {
                amplifier: 0,
                showParticles: false,
            });
        } else if (itemStack.typeId === "fw:fixer") {
            // Removes all effects
            source.runCommandAsync("effect @s clear").catch(() => {});
            source.addEffect("minecraft:nausea", 300, {
                amplifier: 1,
                showParticles: false,
            });
        } else if (itemStack.typeId === "fw:super_stimpack") {
            source.addEffect("minecraft:regeneration", 500, {
                amplifier: 2,
                showParticles: false,
            });
            source.addEffect("minecraft:strength", 300, {
                amplifier: 1,
                showParticles: false,
            });
        } else if (itemStack.typeId === "fw:daddy_o") {
            source.addEffect("minecraft:slowness", 200, {
                amplifier: 1,
                showParticles: false,
            });
            source.addEffect("minecraft:haste", 400, {
                amplifier: 0,
                showParticles: false,
            });
            // Add Rads
            source.runCommandAsync("scoreboard players add @s Rads 3").catch(() => {});
        } else if (itemStack.typeId === "fw:jet") {
            source.addEffect("minecraft:strength", 300, {
                amplifier: 0,
                showParticles: false,
            });
            source.addEffect("minecraft:speed", 300, {
                amplifier: 0,
                showParticles: false,
            });
        } else if (itemStack.typeId === "fw:ultra_jet") {
            source.addEffect("minecraft:strength", 300, {
                amplifier: 1,
                showParticles: false,
            });
            source.addEffect("minecraft:speed", 300, {
                amplifier: 1,
                showParticles: false,
            });
        } else if (itemStack.typeId === "fw:day_tripper") {
            source.addEffect("minecraft:absorption", 300, {
                amplifier: 1,
                showParticles: false,
            });
            source.addEffect("minecraft:slowness", 200, {
                amplifier: 0,
                showParticles: false,
            });
            // Add Rads
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {});
        } else if (itemStack.typeId === "fw:physco_jet") {
            source.addEffect("minecraft:resistance", 500, {
                amplifier: 2,
                showParticles: false,
            });
            source.addEffect("minecraft:speed", 500, {
                amplifier: 1,
                showParticles: false,
            });
            source.addEffect("minecraft:hunger", 200, {
                amplifier: 0,
                showParticles: false,
            });
        } else if (itemStack.typeId === "fw:bufftats") {
            source.addEffect("minecraft:strength", 400, {
                amplifier: 1,
                showParticles: false,
            });
            source.addEffect("minecraft:speed", 400, {
                amplifier: 0,
                showParticles: false,
            });
            // Add Rads
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {});
        } else if (itemStack.typeId === "fw:addictol") {
            // Removes all effects
            source.runCommandAsync("effects @s clear").catch(() => {});
            // Add Rads
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {});
        } else if (itemStack.typeId === "fw:physco") {
            source.addEffect("minecraft:absorption", 1200, {
                amplifier: 1,
                showParticles: false,
            });
            source.addEffect("minecraft:strength", 500, {
                amplifier: 0,
                showParticles: false,
            });
            source.addEffect("minecraft:haste", 500, {
                amplifier: 0,
                showParticles: false,
            });
            source.addEffect("minecraft:weakness", 1000, {
                amplifier: 0,
                showParticles: false,
            });
        } else if (itemStack.typeId === "fw:stealth_boy") {
            source.addEffect("minecraft:invisibility", 500, {
                amplifier: 0,
                showParticles: false,
            });
            source.addEffect("minecraft:slowness", 500, {
                amplifier: 0,
                showParticles: false,
            });
            source.addEffect("minecraft:hunger", 600, {
                amplifier: 0,
                showParticles: false,
            });
        }
    },
};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
    itemComponentRegistry.registerCustomComponent("fw:medical_effects", ItemmedicalEffectsComponent);
});
