import { NextRequest, NextResponse } from 'next/server'; import { getCachedFirm, getKeptRulesFor } from '@/lib/firm-catalog'; import { firmInstruments, instrumentsSource } from '@/lib/instruments'; import { getCredentials } from '@/lib/db'; /** One firm from the cached catalog. Read-only: firms and their account types * are owned by the master dashboard, and there is no local DELETE — a firm * goes away here when it goes away there. */ export async function GET( _req: NextRequest, { params }: { params: Promise<{ id: string }> } ) { const { id } = await params; const firm = getCachedFirm(id); if (!firm) { return NextResponse.json({ error: 'Firm not found' }, { status: 404 }); } const creds = getCredentials(id); return NextResponse.json({ id: firm.id, firm: firm.name, username: creds?.username ?? '', hasCredentials: !!creds, instruments: firmInstruments(firm), instrumentsSource: instrumentsSource(firm), // Same shape as GET /api/firms: each type with its old rule sets' windows. accounts: firm.accountTypes.map((a) => ({ ...a, kept: getKeptRulesFor(a.id).map((k) => ({ id: k.id, openedAt: k.openedAt, closedAt: k.closedAt })), })), catalogUpdatedAt: firm.updatedAt, }); }