<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        \Illuminate\Support\Facades\Event::listen(\Illuminate\Auth\Events\Login::class, function (\Illuminate\Auth\Events\Login $event) {
            \App\Models\Mailbox::where('session_id', \Illuminate\Support\Facades\Session::getId())
                ->whereNull('user_id')
                ->update(['user_id' => $event->user->id]);
        });
    }
}
