/**
 * GET /api/analyzer/itglue/applications/:id/writes
 *
 * Returns the write history for a single asset (for the asset detail page).
 * Auth-only — admins use the same data plus the dedicated /admin/itglue-writes
 * page for cross-asset views.
 */

import { NextRequest, NextResponse } from 'next/server';
import { requireAuth } from '@/lib/auth-utils';
import { listWritesForAsset } from '@/lib/services/analyzer/asset-audit/persistence';

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  const { error } = await requireAuth();
  if (error) return error;
  const { id } = await params;
  const writes = await listWritesForAsset(id, 50);
  return NextResponse.json({ writes });
}
