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

export async function GET(request: NextRequest) {
  const password = process.env.AUTOTASK_SECRET || '';
  
  // Test with the actual password value
  const testUrl = `${process.env.AUTOTASK_API_URL}/Tickets/entityInformation`;
  
  console.log('Password length:', password.length);
  console.log('Password chars:', password.split('').map(c => `${c} (${c.charCodeAt(0)})`).join(', '));
  
  const response = await fetch(testUrl, {
    method: 'GET',
    headers: {
      'Username': process.env.AUTOTASK_USERNAME || '',
      'Secret': password,
      'APIIntegrationcode': process.env.AUTOTASK_API_INTEGRATION_CODE || '',
      'Content-Type': 'application/json',
      'Accept': 'application/json',
    },
  });

  const responseText = await response.text();
  
  return NextResponse.json({
    passwordLength: password.length,
    expectedLength: 25, // The actual password should be 25 chars
    passwordMatches: password === '7g*Zf@K0Ns3#q$E4A1~n2#mW$',
    apiResponse: {
      status: response.status,
      statusText: response.statusText,
      body: responseText.substring(0, 200)
    }
  });
}
