/**
 * GET /api/analyzer/itglue/configurations/:id/writes
 *
 * Per-configuration write history.
 */

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);
  // Filter to configuration writes — listWritesForAsset doesn't filter by
  // asset_type, but a given asset_id only ever exists under one type so this
  // is functionally equivalent. Defensive filter:
  const filtered = writes.filter((w) => w.asset_type === 'configuration');
  return NextResponse.json({ writes: filtered });
}
