"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nginx_1 = require("@yinuo-ngm/nginx");
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
const nginx_binding_store_1 = require("./nginx.binding.store");
exports.default = (0, fastify_plugin_1.default)(async function nginxPlugin(fastify) {
    const nginxApp = new nginx_1.NginxApp();
    fastify.decorate('nginx', nginxApp);
    const persistedPath = await (0, nginx_binding_store_1.loadPersistedNginxPath)();
    if (persistedPath) {
        try {
            await nginxApp.service.bind(persistedPath);
            fastify.log.info(`[nginx] restored binding from ${persistedPath}`);
        }
        catch (error) {
            fastify.log.warn(`[nginx] failed to restore binding from ${(0, nginx_binding_store_1.getNginxBindingStorePath)()}: ${error?.message || error}`);
        }
    }
    fastify.log.info('[nginx] nginx module initialized');
});
