const icing_sweetish_fish_keys = [
    "icing/sweetish_fish/sweetish_fish_red",
    "icing/sweetish_fish/sweetish_fish_green",
    "icing/sweetish_fish/sweetish_fish_yellow",
    "icing/sweetish_fish/sweetish_fish_pink",
    "icing/sweetish_fish/sweetish_fish_blue"
];

TetraJSEvents.workbenchCraft(event => {
    let { player, level, currentSchematic, currentSlot, targetStack, upgradedStack, materials } = event;

    if (!player || !player.getServer()) return;
    if (level.clientSide || !targetStack || !upgradedStack) return

    let armor_module = upgradedStack.getItem().getModuleFromSlot(upgradedStack, currentSlot)
    if (!armor_module || !armor_module instanceof $ItemModuleMajor) return

    for (const key of icing_sweetish_fish_keys) {
        if (!dzzl_has_improvement(armor_module, upgradedStack, key)) {
            return
        }
    }

    icing_sweetish_fish_keys.forEach(key => {
        armor_module.removeImprovement(upgradedStack, key)
    })

    armor_module.addImprovement(upgradedStack, 'armor_all_sweetish_fish', 0)
    

})

const icing_candy_cane_keys = [
    "icing/candy_cane/candy_cane_block",
    "icing/candy_cane/chiseled_candy_cane_block",
    "icing/candy_cane/stripped_candy_cane_block",
    "icing/candy_cane/candy_cane_pole",
    "icing/candy_cane/stripped_candy_cane_pole"
];

TetraJSEvents.workbenchCraft(event => {
    let { player, level, currentSchematic, currentSlot, targetStack, upgradedStack, materials } = event;

    if (!player || !player.getServer()) return;
    if (level.clientSide || !targetStack || !upgradedStack) return;

    let armor_module = upgradedStack.getItem().getModuleFromSlot(upgradedStack, currentSlot);
    if (!armor_module || !armor_module instanceof $ItemModuleMajor) return

    for (const key of icing_candy_cane_keys) {
        if (!dzzl_has_improvement(armor_module, upgradedStack, key)) {
            return;
        }
    }

    icing_candy_cane_keys.forEach(key => {
        armor_module.removeImprovement(upgradedStack, key);
    });

    armor_module.addImprovement(upgradedStack, 'armor_all_candy_cane', 0);
    
});

const icing_rock_candy_keys = [
    "icing/rock_candy/rock_candy_orange",
    "icing/rock_candy/rock_candy_magenta",
    "icing/rock_candy/rock_candy_light_blue",
    "icing/rock_candy/rock_candy_yellow",
    "icing/rock_candy/rock_candy_green",
    "icing/rock_candy/rock_candy_red",
    "icing/rock_candy/rock_candy_black",
    "icing/rock_candy/rock_candy_gray",
    "icing/rock_candy/rock_candy_white",
    "icing/rock_candy/rock_candy_brown",
    "icing/rock_candy/rock_candy_blue",
    "icing/rock_candy/rock_candy_purple",
    "icing/rock_candy/rock_candy_cyan",
    "icing/rock_candy/rock_candy_light_gray",
    "icing/rock_candy/rock_candy_lime",
    "icing/rock_candy/rock_candy_pink"
];

TetraJSEvents.workbenchCraft(event => {
    let { player, level, currentSchematic, currentSlot, targetStack, upgradedStack, materials } = event;

    if (!player || !player.getServer()) return;
    if (level.clientSide || !targetStack || !upgradedStack) return;

    let armor_module = upgradedStack.getItem().getModuleFromSlot(upgradedStack, currentSlot);
    if (!armor_module || !armor_module instanceof $ItemModuleMajor) return

    for (const key of icing_rock_candy_keys) {
        if (!dzzl_has_improvement(armor_module, upgradedStack, key)) {
            return;
        }
    }

    icing_rock_candy_keys.forEach(key => {
        armor_module.removeImprovement(upgradedStack, key);
    });

    armor_module.addImprovement(upgradedStack, 'armor_all_rock_candy', 0);
    
});