package top.r3944realms.lib39.platform;

import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.platform.services.IHelpCommandHook;
import top.r3944realms.lib39.platform.services.IPlatformHelper;
import top.r3944realms.lib39.platform.services.IUtilHelper;

import java.util.Objects;

/**
 * The type Fabric platform helper.
 */
public class FabricPlatformHelper implements IPlatformHelper {

    @Override
    public String getPlatformName() {
        return "Fabric";
    }

    @Override
    public boolean isModLoaded(String modId) {
        return FabricLoader.getInstance().isModLoaded(modId);
    }

    @Override
    public boolean isDevelopmentEnvironment() {

        return FabricLoader.getInstance().isDevelopmentEnvironment();
    }

    @Override
    public boolean isClientEnvironment() {
        return FabricLoader.getInstance().getEnvironmentType().equals(EnvType.CLIENT);
    }

    @Override
    public String getModVersion() {
        return FabricLoader.getInstance().getModContainer(Lib39.MOD_ID)
                .map(ModContainer::getMetadata)
                .map(ModMetadata::getVersion)
                .map(Objects::toString)
                .orElse("NONE");
    }

    @Override
    public IUtilHelper getUtilHelper() {
        return FabricUtilHelper.INSTANCE;
    }

    @Override
    public IHelpCommandHook getHelpCommandHook() {
        return FabricHelpCommandHook.INSTANCE;
    }
}
