<?php

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

use App\Models\Kcd;
use App\Models\User;

echo "=== Updating Pengawas with KCD ===\n\n";

// Get first KCD
$kcd = Kcd::first();
if (!$kcd) {
    echo "No KCD found. Please create KCD first in superadmin menu.\n";
    exit;
}

echo "KCD Found: {$kcd->code} - {$kcd->name}\n\n";

// Get pengawas user
$user = User::find(4);
if ($user) {
    $user->kcd_id = $kcd->id;
    $user->save();
    echo "✓ Updated user: {$user->name} (ID: {$user->id})\n";
    echo "  KCD: {$kcd->code} - {$kcd->name} (ID: {$kcd->id})\n";
} else {
    echo "User ID 4 not found.\n";
}

echo "\nDone!\n";
