<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Login;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Session;

class SuccessfulLogin
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  \Illuminate\Auth\Events\Login  $event
     *
     * @return void
     */
    public function handle(Login $event): void
    {
        Session::put('timezone_name', $event->user->timezone_name);

        // TODO: this may need to be reworked so that the language is stored
        //       in a cookie and attempted to be retrieved from there
        //       first before pulling from the database.
        Session::put('language', $event->user->language->locale);

        // Optionally log the info
        /*
        $loginPayload = [
            'ip_address'  => request()->ip(),
            'email'       => request()->input('email'),
            'happened_at' => gmdate('Y-m-d H:i:s P'),
        ];

        // ...store that payload somewhere.
        */
    }
}
