<?php

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

use App\Modules\PLATFORM\Settings\Models\Company;
use App\Modules\Careers\Models\Job;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

try {
    $company = Company::firstOrCreate(
        ['company_code' => 'TEST01'],
        [
            'legal_name' => 'Test Company',
            'display_name' => 'Test',
            'status' => 1
        ]
    );

    $company->update(['api_key' => 'TEST_API_KEY_123']);

    $job = Job::firstOrCreate(
        ['title' => 'Software Engineer'],
        [
            'company_id' => $company->id,
            'description' => 'Test Job',
            'status' => 'open'
        ]
    );

    // Call API Route
    $request = Request::create('/api/careers/apply', 'POST', [
        'api_key' => 'TEST_API_KEY_123',
        'job_id' => $job->id,
        'name' => 'John API Tester',
        'email' => 'john.apitest@example.com',
        'phone' => '1234567890',
        'gender' => 'Male',
        'age' => 28,
        'city' => 'Colombo',
        'highest_education' => 'BSc Computer Science',
        'experience_years' => '5'
    ]);

    $response = app()->handle($request);
    
    echo "Status: " . $response->getStatusCode() . "\n";
    echo "Body: " . $response->getContent() . "\n";

} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
