package de.winniepat.citrus.cosmetics.hat;

import de.winniepat.citrus.Client;
import software.bernie.geckolib.model.GeoModel;
import net.minecraft.util.Identifier;

public class HatModel extends GeoModel<CosmeticHat> {
    private static final Identifier DEFAULT_HAT_ANIMATION = Identifier.of("citrus", "animations/hat/default_hat.animation.json");
    private static final Identifier DEFAULT_HAT_MODEL = Identifier.of("citrus", "geo/hat/default_hat.geo.json");
    private static final Identifier DEFAULT_HAT_TEXTURE = Identifier.of("citrus", "textures/cosmetics/hat/default_hat.png");

    @Override
    public Identifier getModelResource(CosmeticHat hat) {
        HatType type = hat.getHatType();
        if (type == HatType.NONE) return null;

        Identifier modelId = type.getModelId();
        if (modelId == null) {
            Client.debugLog("Hat model is null for type: " + type.getId());
            return DEFAULT_HAT_MODEL;
        }
        return modelId;
    }

    @Override
    public Identifier getTextureResource(CosmeticHat hat) {
        HatType type = hat.getHatType();
        if (type == HatType.NONE) return null;

        Identifier textureId = type.getTextureId();
        if (textureId == null) {
            Client.debugLog("Hat texture is null for type: " + type.getId());
            return DEFAULT_HAT_TEXTURE;
        }
        return textureId;
    }

    @Override
    public Identifier getAnimationResource(CosmeticHat hat) {
        HatType type = hat.getHatType();
        if (type == HatType.NONE) {
            Client.debugLog("Animation resource is null for NONE hat type");
            return null;
        }

        Identifier anim = type.getAnimationResource();
        if (anim == null) {
            Client.debugLog("Animation resource is null for hat type: " + type.getId());
            Client.debugLog("Falling back to default hat animation");
            return DEFAULT_HAT_ANIMATION;
        }

        Client.debugLog("Hat animation resource: " + anim.toString() + " for type: " + type.getId());
        return anim;
    }
}