/* eslint-disable -- temporary disable for development/testing purposes */

import { NextRequest, NextResponse } from 'next/server';
import mysql from 'mysql2/promise';

// Function to create a DB connection
async function getDBConnection() {
  return mysql.createConnection({
    host: '44.197.53.114',
    user: 'helloprovider',
    password: 'Hello@App12',
    database: 'helloprovider',
  });
}

// GET /api/companies/:id to fetch company details by ID
export async function GET(request: NextRequest, { params }: { params: { id: string } }) {
  try {
    const connection = await getDBConnection();

    // Use parameterized query to fetch company by ID
    const [rows] = await connection.execute(
      'SELECT * FROM comapniese WHERE id = ?',
      [params.id]
    );

    // Close DB connection
    await connection.end();
 
    // Return the first matching company from the query result
    return NextResponse.json(rows);
  } catch (error) {
 
    return NextResponse.json({ error: 'Database query failed' }, { status: 500 });
  }
}
