export const versionRoutes = async (fastify, options) => {
    fastify.get('/api/version/check', async () => {
        return options.checkVersion({ currentVersion: options.currentVersion, forceRefresh: true }, {
            packageVersionGateway: options.packageVersionGateway,
            cache: options.versionCache,
            installTypeDetector: options.installTypeDetector,
        });
    });
    fastify.post('/api/version/update', async (_request, reply) => {
        const result = await options.triggerSelfUpdate({
            selfUpdateCommand: options.selfUpdateCommand,
            installTypeDetector: options.installTypeDetector,
        });
        if (result.status === 'failed') {
            reply.code(500);
        }
        if (result.status === 'permission-denied') {
            reply.code(403);
        }
        if (result.status === 'started') {
            setTimeout(() => {
                options.selfUpdateCommand.restartDaemon(options.serverPort).catch(() => { });
            }, 1000);
        }
        return result;
    });
};
//# sourceMappingURL=version.routes.js.map