<?php

namespace App\Listeners;

use IlluminateAuthEventsPasswordReset;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Support\Facades\Log; // Don't forget to import Log

class LogPasswordReset
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(PasswordReset $event): void
    {
        // Access the user whose password was reset
        $user = $event->user;

        // Log the event
        Log::info('User password reset:', [
            'user_id' => $user->id,
            'email' => $user->email,
            'ip_address' => request()->ip(), // Get the IP address of the request
            'user_agent' => request()->userAgent(), // Get the user agent
            'timestamp' => now()->toDateTimeString(),
        ]);

        // You could also update a 'last_password_change_at' timestamp on the user model
        // $user->forceFill([
        //     'last_password_change_at' => now(),
        // ])->save();
    }
}
