package xyz.quickbasic.tieredrepairkits;

import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import com.hypixel.hytale.server.core.util.Config;

import javax.annotation.Nonnull;


// Main plugin class. All Hytale Java plugins extend JavaPlugin.
public class TieredRepairKits extends JavaPlugin {

    // Logger instance for writing messages to the server console/logs
    public static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();

    // Manager class that will contain the logic related to repair kits
    private RepairKitManager repairKitManager;

    // Config wrapper provided by the Hytale server API.
    // This links the config file name ("TieredRepairKits") with the codec defined in TRKConfig.
    private final Config<TRKConfig> config = this.withConfig("TieredRepairKits", TRKConfig.CODEC);

    // Public getter so other classes (like managers) can access the plugin config
    public Config<TRKConfig> getConfig() {
        return config;
    }

    // Constructor called by the Hytale server when the plugin is created
    public TieredRepairKits(@Nonnull JavaPluginInit init) {
        super(init);
    }

    // Called by the server when the plugin is being set up
    @Override
    protected void setup() {

        // Create the RepairKitManager and pass the plugin instance to it
        // This allows the manager to access config, logger, etc.
        repairKitManager = new RepairKitManager(this);

        // Save the config file if it does not exist yet
        // This ensures defaults from TRKConfig are written to disk
        config.save();
    }

}