<?php

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

echo "=== Legal Agreements Table Check ===\n\n";

try {
    // Check if table exists
    $tableExists = Schema::hasTable('legal_agreements');
    echo "Table 'legal_agreements' exists: " . ($tableExists ? "YES ✓" : "NO ✗") . "\n\n";
    
    if ($tableExists) {
        // Get table columns
        echo "Table Columns:\n";
        $columns = DB::select("DESCRIBE legal_agreements");
        foreach ($columns as $column) {
            echo "  - {$column->Field} ({$column->Type}) " . ($column->Null === 'YES' ? 'nullable' : 'required') . "\n";
        }
        
        // Count records
        echo "\nTotal records: " . DB::table('legal_agreements')->count() . "\n";
        
        // Show sample records if any exist
        $agreements = DB::table('legal_agreements')->get();
        if ($agreements->count() > 0) {
            echo "\nSample Records:\n";
            foreach ($agreements as $agreement) {
                echo "  ID: {$agreement->id}\n";
                echo "    User ID: {$agreement->user_id}\n";
                echo "    Marketing Officer ID: {$agreement->marketing_officer_id}\n";
                echo "    Status: {$agreement->status}\n";
                echo "    Original File: {$agreement->original_file_path}\n";
                echo "    Signed File: {$agreement->signed_file_path}\n";
                echo "    Created: {$agreement->created_at}\n";
                echo "    ---\n";
            }
        }
    }
    
} catch (\Exception $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
    echo "Trace: " . $e->getTraceAsString() . "\n";
}

echo "\n=== Check Complete ===\n";
