<?php

namespace Modules\Bms\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * The module namespace to assume when generating URLs to actions.
     */
    protected $moduleNamespace = 'Modules\Bms\Http\Controllers';

    public function boot(): void
    {
        parent::boot();
    }

    public function map(): void
    {
        $this->mapApiRoutes();
        $this->mapWebRoutes();
    }

    /**
     * P1 Blade back-office — session-authenticated, inside the ERP UI.
     */
    protected function mapWebRoutes(): void
    {
        Route::middleware('web')
            ->namespace($this->moduleNamespace)
            ->group(__DIR__ . '/../Routes/web.php');
    }

    /**
     * Versioned REST API consumed by the two Angular PWAs.
     * Guards (employee / client) are applied per route-group inside api.php.
     */
    protected function mapApiRoutes(): void
    {
        Route::prefix('api/v1/bms')
            ->middleware('api')
            ->name('bms.api.')
            ->namespace($this->moduleNamespace . '\Api')
            ->group(__DIR__ . '/../Routes/api.php');
    }
}
