/*
 *  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.content.animation;


import com.google.common.collect.Sets;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.eroticdungeongame.EroticDungeon;
import top.r3944realms.eroticdungeongame.content.block.ISeatBlock;
import top.r3944realms.eroticdungeongame.content.block.type.*;

import java.util.HashSet;
import java.util.Set;

public enum EDGAnimations implements IEDGAnimation {
    CUFF_BED("cuff_bed", CuffBedBlock.class),
    PRONE_BENCH("prone_bench", ProneBenchBlock.class),
    IRON_CAGE("iron_cage", IronCageBlock.class),
    SPANISH_DONKEY("spanish_donkey", SpanishDonkeyBlock.class),
    HANGING_POST("hanging_post", HangingPostBlock.class),
    CUFF_POLE("cuff_pole", CuffPoleBlock.class),
    CRUX("crux", CruxBlock.class),
    PETRINE_CROSS("petrine_cross", PetrineCrossBlock.class),
    PILLORY("pillory", PilloryBlock.class),
    RACK("rack", RackBlock.class),
    WALL_RACK("wall_rack", WallRackBlock.class),
    X_CROSS("x_cross", XCrossBlock.class),
    DISPLAY_RACK("display_rack", DisplayRackBlock.class),
    GLASS_DISPLAY_RACK("glass_display_rack", GlassDisplayRackBlock.class),;
    private final ResourceLocation baseId;
    private final Class<?> blockClass;

    EDGAnimations(String baseId, Class<?> blockClass) {
        this.baseId = EroticDungeon.rl(baseId + "_pose_");
        this.blockClass = blockClass;
    }
    private static final Set<IEDGAnimation> extraAnimations = new HashSet<>();

    public static void registerExtraAnimation(IEDGAnimation animation) {
        extraAnimations.add(animation);
    }

    public static @NotNull Set<IEDGAnimation> getExtraAnimations() {
        return Sets.newHashSet(extraAnimations);
    }

    @Nullable
    public static IEDGAnimation getAnimation(@NotNull Class<?> blockClass) {
        if (ISeatBlock.class.isAssignableFrom(blockClass)) {
            for (EDGAnimations value : values()) {
                if (value.blockClass.equals(blockClass)) {
                    return value;
                }
            }
            for (IEDGAnimation extraAnimation : extraAnimations) {
                if (extraAnimation.getBlockClass().equals(blockClass)) {
                    return extraAnimation;
                }
            }
        }
        return null;
    }

    @Override
    public ResourceLocation getBaseId() {
        return baseId;
    }

    @Override
    public Class<?> getBlockClass() {
        return blockClass;
    }
}
