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

import net.minecraft.world.entity.Entity;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.eventbus.api.IEventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.r3944realms.eroticdungeongame.api.capability.IPlayerDungeonData;
import top.r3944realms.eroticdungeongame.api.workspace.Services;
import top.r3944realms.eroticdungeongame.content.capability.AbstractPlayerDungeonData;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * The type Erotic dungeon game api.
 */
public class EroticDungeonGameApi {
    /**
     * The constant LOGGER.
     */
    public static final Logger LOGGER = LoggerFactory.getLogger(EroticDungeonGameApi.class);
    /**
     * The constant MOD_ID.
     */
    public static final String MOD_ID = "eroticdungeongame"; //Erotic Dungeon Game
    /**
     * The constant PLAYER_DUNGEON_DATA_CAP.
     */
    public static final Capability<AbstractPlayerDungeonData> PLAYER_DUNGEON_DATA_CAP = CapabilityManager.get(new CapabilityToken<>() {});

    /**
     * Gets mod event bus.
     *
     * @return the mod event bus
     */
    public static IEventBus getModEventBus() {
        return Services.WORK_SPACE.getModEventBus();
    }

    /**
     * Is in device boolean.
     *
     * @param player the player
     * @return the boolean
     */
    public static boolean isInDevice(Entity player) {
        return Services.WORK_SPACE.isInDevice(player);
    }

    /**
     * Try to do if in device.
     *
     * @param player   the player
     * @param action   the action
     * @param fallback the fallback
     */
    public static void tryToDoIfInDevice(Entity player, Consumer<IPlayerDungeonData> action, Runnable fallback) {
        Services.WORK_SPACE.tryToDoIfInDevice(player, action, fallback);
    }

    /**
     * Try to do if in device.
     *
     * @param player the player
     * @param action the action
     */
    public static void tryToDoIfInDevice(Entity player,Consumer<IPlayerDungeonData> action) {
        Services.WORK_SPACE.tryToDoIfInDevice(player, action);
    }

    /**
     * Try to do if in device and ret t.
     *
     * @param <T>      the type parameter
     * @param player   the player
     * @param action   the action
     * @param fallback the fallback
     * @return the t
     */
    public static <T> T tryToDoIfInDeviceAndRet(Entity player, Function<IPlayerDungeonData, T> action, Supplier<T> fallback) {
        return  Services.WORK_SPACE.tryToDoIfInDeviceAndRet(player, action, fallback);
    }

    /**
     * Try to do if in device and ret t.
     *
     * @param <T>    the type parameter
     * @param player the player
     * @param action the action
     * @return the t
     */
    public static <T> T tryToDoIfInDeviceAndRet(Entity player, Function<IPlayerDungeonData, T> action) {
        return Services.WORK_SPACE.tryToDoIfInDeviceAndRet(player, action);
    }

    /**
     * Check is player boolean.
     *
     * @param entity the entity
     * @return the boolean
     */
    public static boolean checkIsPlayer(Entity entity) {
        return Services.WORK_SPACE.checkIsPlayer(entity);
    }
}
