import { RegistryClient } from '@expxagents/registry-client';
const REGISTRY_URL = process.env.EXPX_REGISTRY_URL || 'https://expxagents-marketplace-production.up.railway.app';
export async function registryRoutes(app, opts) {
    const client = new RegistryClient({ registryUrl: REGISTRY_URL });
    // GET /api/registry/categories
    app.get('/api/registry/categories', async () => {
        return client.getCategories();
    });
    // GET /api/registry/squads
    app.get('/api/registry/squads', async (req) => {
        const { q, category, sort, page, limit } = req.query;
        return client.search({
            q,
            category,
            sort: sort,
            page: page ? parseInt(page) : undefined,
            limit: limit ? parseInt(limit) : undefined,
        });
    });
    // GET /api/registry/squads/:id
    app.get('/api/registry/squads/:id', async (req) => {
        const { id } = req.params;
        if (id.startsWith('@')) {
            return client.getSquad(id);
        }
        // Legacy UUID — not supported by global registry
        return { error: 'Legacy squad IDs are no longer supported. Use @scope/name format.' };
    });
    // POST /api/registry/squads/:id/install
    app.post('/api/registry/squads/:id/install', {
        preHandler: [app.requireAuth],
    }, async (req) => {
        const { id } = req.params;
        const fullName = id.startsWith('@') ? id : `@unknown/${id}`;
        const result = await client.installWithDeps(fullName, 'latest', opts.squadsDir);
        return { success: true, installed: result };
    });
    // POST /api/registry/squads/publish — CLI-only
    app.post('/api/registry/squads/publish', {
        preHandler: [app.requireAuth],
    }, async () => {
        return { error: 'Publishing is only available via CLI. Run: expxagents publish', code: 'CLI_ONLY' };
    });
    // POST /api/registry/squads/:id/rate — CLI-only for v1
    app.post('/api/registry/squads/:id/rate', {
        preHandler: [app.requireAuth],
    }, async () => {
        return { error: 'Rating is only available via CLI.', code: 'CLI_ONLY' };
    });
}
//# sourceMappingURL=registry-routes.js.map