<?php

use App\Models\User;
use Illuminate\Support\Facades\Hash;

require __DIR__ . '/vendor/autoload.php';
$app = require_once __DIR__ . '/bootstrap/app.php';

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

$email = 'admin-diagnostika@ds-innovacion.com';
$password = 'oweAaNzzpa(Z';

try {
    // Buscar si ya existe el usuario
    $user = User::where('email', $email)->first();

    if ($user) {
        $user->update([
            'password' => Hash::make($password),
            'role' => 'admin',
            'name' => 'Administrador Maestro'
        ]);
        echo "Usuario administrador actualizado correctamente.\n";
    } else {
        User::create([
            'name' => 'Administrador Maestro',
            'email' => $email,
            'password' => Hash::make($password),
            'role' => 'admin'
        ]);
        echo "Usuario administrador creado correctamente.\n";
    }
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
