<?php

namespace App\Providers;

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

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    protected $api_namespace = 'App\Http\Controllers\Api';

    protected $wechat_namespace = 'App\Http\Controllers\WeChat';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

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

        $this->mapWebRoutes();

        //后台路由
        $this->mapAdminRoutes();

        $this->mapTeacherRoutes();

        $this->mapWeChatRoutes();
    }

    public function mapAdminRoutes()
    {
        Route::prefix('admin')
            ->middleware('web')
            ->namespace($this->namespace. '\Admin')
            ->group(base_path('routes/admin.php'));
    }

    public function mapTeacherRoutes()
    {
        Route::prefix('teacher')
            ->middleware('web')
            ->namespace($this->namespace. '\Teacher')
            ->group(base_path('routes/teacher.php'));
    }

    public function mapWeChatRoutes()
    {
        Route::prefix('wechat')
            ->middleware('web')
            ->namespace($this->wechat_namespace)
            ->group(base_path('routes/wechat.php'));
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->api_namespace)
             ->group(base_path('routes/api.php'));
    }
}
