<?php
require 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();

$apiKey = env('SANDBOX_API_KEY');
$apiSecret = env('SANDBOX_API_SECRET');
$baseUrl = 'https://api.sandbox.co.in/';

// Authenticate
$authResponse = \Illuminate\Support\Facades\Http::withHeaders([
    'x-api-key' => $apiKey,
    'x-api-secret' => $apiSecret,
    'x-api-version' => '1.0.0',
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
])->post($baseUrl . 'authenticate');

$authData = $authResponse->json();
if (!$authResponse->successful() || !isset($authData['access_token'])) {
    die("Auth failed: " . print_r($authData, true));
}
$token = $authData['access_token'];

$pan = 'AUBPV9763E';

$payloads = [
    'entity_with_pan_only' => [
        '@entity' => 'in.co.sandbox.kyc.pan_verification.request',
        'pan' => $pan
    ],
    'entity_with_pan_consent_reason' => [
        '@entity' => 'in.co.sandbox.kyc.pan_verification.request',
        'pan' => $pan,
        'consent' => 'y',
        'reason' => 'Customer verification for onboarding'
    ],
    'entity_with_pan_name_dob_consent_reason' => [
        '@entity' => 'in.co.sandbox.kyc.pan_verification.request',
        'pan' => $pan,
        'name_as_per_pan' => '',
        'date_of_birth' => '',
        'consent' => 'y',
        'reason' => 'Customer verification for onboarding'
    ]
];

foreach ($payloads as $name => $payload) {
    echo "\n----------------------------------------\n";
    echo "Testing payload: $name\n";
    echo "Payload: " . json_encode($payload) . "\n";
    
    $response = \Illuminate\Support\Facades\Http::withHeaders([
        'x-api-key' => $apiKey,
        'authorization' => $token,
        'x-api-version' => '1.0.0',
        'Accept' => 'application/json',
        'Content-Type' => 'application/json',
    ])->post($baseUrl . 'kyc/pan/verify', $payload);
    
    echo "Response Status: " . $response->status() . "\n";
    print_r($response->json());
}
