<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport;

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

    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        // Add custom claims to tokens for OIDC compatibility
        Passport::tokensCan([
            'openid' => 'OpenID Connect',
            'profile' => 'Access to profile information',
            'email' => 'Access to email address',
        ]);

        // Customize the user data included in JWT tokens
        Passport::withCookieSerialization();

        // This event listener adds custom claims to the JWT token
        app('events')->listen(
            \Laravel\Passport\Events\AccessTokenCreated::class,
            function ($event) {
                // This is handled by the custom package via claims
                // The actual JWT enhancement happens in the custom JWT claims
                // through the patches we applied to the ronvanderheijden/openid-connect package
            }
        );
    }
}
