<?php

namespace Boilerplate\Boilerplate\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Routing\Router;
use Boilerplate\Boilerplate\Models\Boilerplate;
use Request;

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

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @param   \Illuminate\Routing\Router  $router
     * @return void
     */
    public function boot(Router $router)
    {
        parent::boot($router);

        if (Request::is('*/boilerplate/boilerplate/*')) {
            $router->bind('boilerplate', function ($id) {
                $boilerplate = $this->app->make('\Boilerplate\Boilerplate\Interfaces\BoilerplateRepositoryInterface');
                return $boilerplate->findorNew($id);
            });
        }if (Request::is('*/boilerplate/boilerplate_i18n/*')) {
            $router->bind('boilerplate_i18n', function ($id) {
                $boilerplate_i18n = $this->app->make('\Boilerplate\Boilerplate\Interfaces\BoilerplateI18nRepositoryInterface');
                return $boilerplate_i18n->findorNew($id);
            });
        }

    }

    /**
     * Define the routes for the application.
     *
     * @param \Illuminate\Routing\Router $router
     *
     * @return void
     */
    public function map(Router $router)
    {
        $router->group(['namespace' => $this->namespace], function ($router) {
            require __DIR__ . '/../Http/routes.php';
        });
    }
}