<?php

namespace App\Listeners;

use Illuminate\Support\Facades\Log;

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

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        $user = $event->user;

        if (! $user) {
            return;
        }

        Log::channel('auth_activity')
            ->info(sprintf(
                '%s, APP_NAME: %s, REQUEST_TYPE: %s, SOURCE_IP: %s, SOURCE_PORT: %s, SOURCE_URL: %s, DESTINATION_IP: %s, DESTINATION_PORT: %s, DESTINATION_COUNTRY: %s',
                'LOGOUT',
                config('app.name'),
                request()->method(),
                request()->ip(),
                $_SERVER['REMOTE_PORT'],
                request()->url(),
                request()->host(),
                request()->getPort(),
                'tk',
            ));
    }
}
