<?php

namespace Modules\Mall\Providers;

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

class RouteServiceProvider extends ServiceProvider
{

    /**
     * @var string $moduleName
     */
    protected string $moduleName = 'Mall';

    /**
     * The module namespace to assume when generating URLs to actions.
     * @var string
     */
    protected string $moduleNamespace = 'Modules\Mall\Http\Controllers';

    /**
     * Called before routes are registered.
     * Register any model bindings or pattern based filters.
     * @return void
     */
    public function boot()
    {
        parent::boot();
    }

    /**
     * Define the routes for the application.
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapAdminRoutes();

        $this->mapAgentRoutes();
    }

    protected function mapApiRoutes()
    {
        Route::as(config('api.route.as'))
             ->domain(config('api.route.domain'))
             ->middleware(config('api.route.middleware'))
             ->namespace($this->moduleNamespace)
             ->prefix(config('api.route.prefix'))
             ->group(module_path($this->moduleName, 'Routes/api.php'));
    }

    protected function mapAdminRoutes()
    {
        Route::as(config('admin.route.as'))
             ->domain(config('admin.route.domain'))
             ->middleware(config('admin.route.middleware'))
             ->namespace($this->moduleNamespace)
             ->prefix(config('admin.route.prefix'))
             ->group(module_path($this->moduleName, 'Routes/admin.php'));
    }

    /**
     * Notes   : 中台路由
     * @Date   : 2021/5/7 9:25 上午
     * @Author : < Jason.C >
     */
    protected function mapAgentRoutes()
    {
        Route::as(config('agent.route.as'))
             ->domain(config('agent.route.domain'))
             ->middleware(array_merge(config('agent.route.middleware_auth'), ['agent.auth']))
             ->namespace($this->moduleNamespace)
             ->prefix(config('agent.route.prefix'))
             ->group(module_path($this->moduleName, 'Routes/agent.php'));
    }

}
