package com.r3944realms.leashedplayer.utils.dataModel;

import com.r3944realms.leashedplayer.client.renderer.item.ConditionalRangeItemModel;
import com.r3944realms.leashedplayer.client.renderer.item.properties.conditionalRange.ConditionalRangeItemModelProperty;
import net.minecraft.client.data.models.model.ModelTemplate;
import net.minecraft.client.data.models.model.TextureMapping;
import net.minecraft.client.renderer.item.ItemModel;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

import java.util.List;
import java.util.Optional;

@OnlyIn(Dist.CLIENT)
public class ItemModelUtils {
    public static ItemModel.Unbaked conditionalRange(
            ConditionalRangeItemModelProperty property, float scale, ItemModel.Unbaked fallback, ConditionalRangeItemModel.Entry[] onTrue, ConditionalRangeItemModel.Entry[] onFalse
    ) {
        return new ConditionalRangeItemModel.Unbaked(property, scale, List.of(onTrue), List.of(onFalse), Optional.of(fallback));
    }
    public static ItemModel.Unbaked conditionalRange(
            ConditionalRangeItemModelProperty property, float scale, ConditionalRangeItemModel.Entry[] onTrue, ConditionalRangeItemModel.Entry[] onFalse
    ) {
        return new ConditionalRangeItemModel.Unbaked(property, scale, List.of(onTrue), List.of(onFalse), Optional.empty());
    }
    public static ItemModel.Unbaked conditionalRange(
            ConditionalRangeItemModelProperty property, ConditionalRangeItemModel.Entry[] onTrue, ConditionalRangeItemModel.Entry[] onFalse
    ) {
        return new ConditionalRangeItemModel.Unbaked(property, 1.0F, List.of(onTrue), List.of(onFalse), Optional.empty());
    }
    public static ItemModel.Unbaked conditionalRange(
            ConditionalRangeItemModelProperty property, ItemModel.Unbaked fallback, ConditionalRangeItemModel.Entry[] onTrue, ConditionalRangeItemModel.Entry[] onFalse
    ) {
        return new ConditionalRangeItemModel.Unbaked(property, 1.0F, List.of(onTrue), List.of(onFalse), Optional.of(fallback));
    }
    public static ConditionalRangeItemModel.Entry override(ItemModel.Unbaked threshold, float model) {
        return new ConditionalRangeItemModel.Entry(model, threshold);
    }
    public static ResourceLocation createFlatItemModelByPath(String MOD_ID, String path, ModelTemplate modelTemplate, java. util. function. BiConsumer<ResourceLocation, net. minecraft. client. data. models. model. ModelInstance> consumer ) {
        return modelTemplate.create(
                ResourceLocation.fromNamespaceAndPath(MOD_ID, path),
                TextureMapping.layer0(ResourceLocation.fromNamespaceAndPath(MOD_ID, path)),
                consumer
        );
    }
}
