import * as vscode from "vscode";
import { runUpdater, manualUpdateCheck } from "./updater";

// ================= LOGGING SETUP =================
export const updaterOutput = vscode.window.createOutputChannel("Updater Startup");

export function logDebug(...args: any[]) {
    const message = args
        .map(a => (typeof a === "object" ? JSON.stringify(a, null, 2) : a))
        .join(" ");
    updaterOutput.appendLine(message);
    console.log(message); // optional, still shows in DevTools
    updaterOutput.show(true);
}

export function activate(context: vscode.ExtensionContext) {
    logDebug("[Extension] Activating extension..."); // test log

    // Run automatic updater
    runUpdater(context);

    // Register manual update check command
    const disposable = vscode.commands.registerCommand(
        "cstmgames.fivem_snippets.checkUpdates",
        () => manualUpdateCheck(context)
    );
    context.subscriptions.push(disposable);
}

export function deactivate() {}