import { NextRequest, NextResponse } from 'next/server';
import postgresClient from '@/lib/services/postgres-client';

export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ companyId: string }> }
) {
  try {
    const { companyId } = await params;
    const companyIdInt = parseInt(companyId);

    const result = await postgresClient.query(`
      SELECT
        cr.*,
        c.company_name
      FROM veeam_compliance_results cr
      LEFT JOIN companies c ON c.id = cr.company_id
      WHERE cr.company_id = $1
      ORDER BY cr.mismatch_type, cr.device_name
    `, [companyIdInt]);

    return NextResponse.json(result.rows);
  } catch (error) {
    console.error('[VEEAM-API] company compliance error:', error);
    return NextResponse.json([]);
  }
}
