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 result = await postgresClient.query(`
      SELECT pw.*
      FROM veeam_protected_workloads pw
      JOIN veeam_organizations vo ON vo.instance_uid = pw.organization_uid
      WHERE vo.company_id = $1
      ORDER BY pw.name
    `, [parseInt(companyId)]);

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