import { Shield } from '@4runr/shield';
import { requireAuth } from '../middleware/auth.js';
import { readRateLimit, writeRateLimit } from '../middleware/rateLimit.js';
export async function shieldRoutes(fastify) {
    const shield = Shield.getInstance();
    fastify.get('/api/shield/health', {
        preHandler: [requireAuth, readRateLimit],
    }, async (_request, reply) => {
        try {
            const health = shield.getHealth();
            return {
                success: true,
                ...health,
                timestamp: new Date().toISOString(),
            };
        }
        catch (error) {
            const msg = error instanceof Error ? error.message : String(error);
            return reply.status(500).send({
                error: 'Failed to get Shield health',
                details: msg,
            });
        }
    });
    fastify.get('/api/shield/config', {
        preHandler: [requireAuth, readRateLimit],
    }, async (_request, reply) => {
        try {
            const config = shield.getConfig();
            return {
                success: true,
                config,
            };
        }
        catch (error) {
            const msg = error instanceof Error ? error.message : String(error);
            return reply.status(500).send({
                error: 'Failed to get Shield config',
                details: msg,
            });
        }
    });
    fastify.post('/api/shield/check-input', {
        preHandler: [requireAuth, writeRateLimit],
    }, async (request, reply) => {
        try {
            const body = request.body;
            const input = body.input || body;
            const decision = shield.checkInput(input);
            return {
                success: true,
                decision,
            };
        }
        catch (error) {
            const msg = error instanceof Error ? error.message : String(error);
            return reply.status(500).send({
                error: 'Failed to check input',
                details: msg,
            });
        }
    });
    fastify.post('/api/shield/check-output', {
        preHandler: [requireAuth, writeRateLimit],
    }, async (request, reply) => {
        try {
            const body = request.body;
            const input = body.input || {};
            const output = body.output || body;
            const decision = shield.checkOutput(input, output);
            return {
                success: true,
                decision,
            };
        }
        catch (error) {
            const msg = error instanceof Error ? error.message : String(error);
            return reply.status(500).send({
                error: 'Failed to check output',
                details: msg,
            });
        }
    });
}
//# sourceMappingURL=shield.js.map