<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Login;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use App\Models\LoginLog;

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

    /**
     * Handle the event.
     */
    public function handle(Login $event): void
    {
        // Ambil data user yang login
        $user = $event->user;

        // Simpan log login
        LoginLog::create([
            'user_id'    => $user->id ?? null,
            'ip_address' => request()->ip(),
            'user_agent' => request()->userAgent(),
            'status'     => 'login',
        ]);
    }
}
