package top.r3944realms.lib39;

import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.r3944realms.lib39.example.Lib39Example;
import top.r3944realms.lib39.platform.Services;

/**
 * The type Lib 39.
 */
public class Lib39 {
	/**
	 * The constant MOD_ID.
	 */
	public static final String MOD_ID = "lib39";
	/**
	 * The constant MOD_NAME.
	 */
	public static final String MOD_NAME = "3944Realms 's Lib Mod";
	/**
	 * The constant LOGGER.
	 */
	public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
	/**
	 * The constant ENABLE_EXAMPLES_PROPERTY_KEY.
	 */
	public static final String ENABLE_EXAMPLES_PROPERTY_KEY = "lib39.enable_examples";

	/**
	 * Initialize.
	 */
	public static void initialize() {
		Lib39.LOGGER.info("[Lib39-Common] Lib39-Common start initialization.");
		if (shouldRegisterExamples()) {
			LOGGER.info("[Lib39-Common] Registering Examples");
			registerExamples();
		}
		Lib39.LOGGER.info("[Lib39-Common] Finished Lib39-Common!.");
	}

	/**
	 * Rl resource location.
	 *
	 * @param path the path
	 * @return the resource location
	 */
	@Contract("_ -> new")
	public static @NotNull Identifier rl(String path) {
		return Identifier.fromNamespaceAndPath(Lib39.MOD_ID, path);
	}

	/**
	 * Rl resource location.
	 *
	 * @param modId the mod id
	 * @param path  the path
	 * @return the resource location
	 */
	@Contract("_, _ -> new")
	public static @NotNull Identifier rl(String modId, String path) {
		return Identifier.fromNamespaceAndPath(modId, path);
	}

	/**
	 * Mrl resource location.
	 *
	 * @param path the path
	 * @return the resource location
	 */
	@Contract("_ -> new")
	public static @NotNull Identifier mrl(String path) {
		return Identifier.withDefaultNamespace(path);
	}

	/**
	 * Is client environment boolean.
	 *
	 * @return the boolean
	 */
	public static boolean isClientEnvironment() {
		return Services.PLATFORM.isClientEnvironment();
	}

	/**
	 * Should register examples boolean.
	 *
	 * @return the boolean
	 */
	public static boolean shouldRegisterExamples() {
		return Services.PLATFORM.isDevelopmentEnvironment() || Boolean.getBoolean(ENABLE_EXAMPLES_PROPERTY_KEY);
	}


	/**
	 * Register examples.
	 */
	static void registerExamples() {
		LOGGER.info("[Lib39-Common] Starting example demonstrations");
		try {
			// 创建示例实例并演示功能
			Lib39Example example = new Lib39Example();
			example.demonstrateFeature();

			LOGGER.info("[Lib39-Common] Example demonstrations completed successfully");
		} catch (Exception e) {
			LOGGER.error("[Lib39-Common] Failed to demonstrate examples", e);
		}
	}

	/**
	 * The type Mod info.
	 */
	public static class ModInfo {
		/**
		 * The constant VERSION.
		 */
		public static final String VERSION;
		static {
			VERSION = Services.PLATFORM.getModVersion();
		}
	}
}