/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.datagen.provider;

import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.eroticdungeongame.EroticDungeon;
import top.r3944realms.eroticdungeongame.util.ColorContent;
import top.r3944realms.eroticdungeongame.util.WoodTypeHelper;

public class EDGItemModelProvider extends ItemModelProvider {
    public EDGItemModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
        super(output, EroticDungeon.MOD_ID, existingFileHelper);
    }

    @Override
    protected void registerModels() {
        generateWhipItemModel();
        generateCuffBedItemModels();
        generateIronCageItemModel();
        generateAllWoodenItemModels();
        generateSpanishDonkeyItemModels();
        generateDungeonCraftingTableItemModel();
        generateLoveMachineItemItemModel();
    }

    protected void generateWhipItemModel() {
        getBuilder("whip")
                .texture("layer0", "item/whip")
                .parent(getExistingFile(EroticDungeon.mrl("item/handheld")));
    }

    protected void generateDungeonCraftingTableItemModel() {
        getBuilder("dungeon_crafting_table")
                .parent(getExistingFile(EroticDungeon.rl("block/dungeon_crafting_table")));
    }

    protected void generateIronCageItemModel() {
        getBuilder("iron_cage")
                .parent(getExistingFile(EroticDungeon.rl("block/iron_cage")));
    }

    protected void generateLoveMachineItemItemModel() {
        getBuilder("end_rod_love_machine")
                .parent(getExistingFile(EroticDungeon.rl("block/love_machine")));
        getBuilder("lightning_rod_love_machine")
                .parent(getExistingFile(EroticDungeon.rl("block/love_machine")));
    }

    protected void generateSpanishDonkeyItemModels() {
        for (WoodType woodType : WoodTypeHelper.SUPPORTED_WOOD_TYPES){
            getBuilder(woodType.name() + "_spanish_donkey")
                    .parent(getExistingFile(EroticDungeon.rl("block/spanish_donkey/" + woodType.name())));
        }
    }

    protected void generateCuffBedItemModels() {
        for (String color : ColorContent.COLORS) {
            // 为每种颜色的床物品创建模型
            createCuffBedItemModel(color);
        }
    }

    protected void generateAllWoodenItemModels() {
        for (WoodType woodType : WoodTypeHelper.SUPPORTED_WOOD_TYPES) {
            createXCrossItemModel(woodType);
            createPetrineCrossItemModel(woodType);
            createCruxItemModel(woodType);
            createRackItemModel(woodType);
            createPilloryItemModel(woodType);
            createWallRackItemModel(woodType);
            createCuffPoleItemModel(woodType);
            createHangingPostItemModel(woodType);
            for (String color : ColorContent.COLORS) {
                createProneBenchItemModel(color, woodType);
            }
        }
    }

    private void createCuffPoleItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_cuff_pole";
        ResourceLocation rl = WoodTypeHelper.getWoodLogRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_cuff_pole")))
                .texture("wood", rl);
    }
    private void createProneBenchItemModel(@NotNull String color, @NotNull WoodType wood) {
        String itemName =  color + "_" + wood.name() + "_prone_bench";
        ResourceLocation woodRl = WoodTypeHelper.getStrippedWoodRL(wood);
        ResourceLocation woolRl = EroticDungeon.mrl("block/" + color + "_wool");
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("block/base_prone_bench")))
                .texture("wool", woolRl)
                .texture("wood", woodRl);
    }

    private void createRackItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_rack";
        ResourceLocation rl = WoodTypeHelper.getStrippedWoodRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_rack")))
                .texture("wood", rl);
    }

    private void createCuffBedItemModel(String color) {
        String itemName = color + "_cuff_bed";
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_cuff_bed")))
                .texture("bed", EroticDungeon.rl("block/bed/" + color));
    }

    private void createXCrossItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_x_cross";
        ResourceLocation rl = WoodTypeHelper.getStrippedWoodRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_x_cross")))
                .texture("wood", rl);
    }

    private void createCruxItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_crux";
        ResourceLocation rl = WoodTypeHelper.getWoodPlankRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_crux")))
                .texture("wood", rl);
    }

    private void createPetrineCrossItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_petrine_cross";
        ResourceLocation rl = WoodTypeHelper.getWoodPlankRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_petrine_cross")))
                .texture("wood", rl);
    }

    private void createHangingPostItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_hanging_post";
        ResourceLocation rl = WoodTypeHelper.getStrippedWoodRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_hanging_post")))
                .texture("wood", rl);
    }

    private void createPilloryItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_pillory";
        ResourceLocation rl = WoodTypeHelper.getWoodPlankRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_pillory")))
                .texture("wood", rl);
    }

    private void createWallRackItemModel(@NotNull WoodType wood) {
        String itemName = wood.name() + "_wall_rack";
        ResourceLocation woodPlankRL = WoodTypeHelper.getWoodPlankRL(wood);
        ResourceLocation woodLogRL = WoodTypeHelper.getWoodLogRL(wood);
        getBuilder(itemName)
                .parent(getExistingFile(EroticDungeon.rl("item/base_wall_rack")))
                .texture("plank", woodPlankRL)
                .texture("wood", woodLogRL);
    }
}
