<?php

namespace App\Providers;  // Keep only this namespace

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        // The current NGBVD database already has Sanctum/Passport token tables.
        // Ignore package-loaded migrations to prevent "table already exists" failures
        // such as personal_access_tokens, oauth_access_tokens, etc. Published/safe
        // application migrations remain available from database/migrations.
        if (class_exists(\Laravel\Sanctum\Sanctum::class)) {
            \Laravel\Sanctum\Sanctum::ignoreMigrations();
        }

        if (class_exists(\Laravel\Passport\Passport::class) && method_exists(\Laravel\Passport\Passport::class, 'ignoreMigrations')) {
            \Laravel\Passport\Passport::ignoreMigrations();
        }
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        View::composer('*', function ($view) {
            try {
                $licenseAlert = getLicenseExpiryAlert('Advanced Report');
            } catch (\Exception $e) {
                $licenseAlert = null;
            }
            $view->with('licenseAlert', $licenseAlert);
        });
    }
}
