<?php

namespace App\Listeners;

use App\Models\AdminLog;
use Illuminate\Auth\Events\Failed;

class LogFailedLoginAttempt
{
    public function handle(Failed $event): void
    {
        AdminLog::create([
            'admin_id' => null,
            'action' => 'failed_login',
            'target_type' => 'user',
            'target_id' => null,
            'old_values' => null,
            'new_values' => [
                'email' => $event->credentials['email'] ?? 'unknown',
            ],
            'ip_address' => request()->ip(),
            'created_at' => now(),
        ]);
    }
}
