<?php

namespace Clientes\Cliente\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Routing\Router;
use Clientes\Cliente\Models\Cliente;
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 = 'Clientes\Cliente\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('*/cliente/cliente/*')) {
            $router->bind('cliente', function ($id) {
                $cliente = $this->app->make('\Clientes\Cliente\Interfaces\ClienteRepositoryInterface');
                return $cliente->findorNew($id);
            });
        }if (Request::is('*/cliente/cliente/*')) {
            $router->bind('cliente', function ($id) {
                $cliente = $this->app->make('\Clientes\Cliente\Interfaces\ClienteRepositoryInterface');
                return $cliente->findorNew($id);
            });
        }if (Request::is('*/cliente/arquivo/*')) {
            $router->bind('arquivo', function ($id) {
                $arquivo = $this->app->make('\Clientes\Cliente\Interfaces\ArquivoRepositoryInterface');
                return $arquivo->findorNew($id);
            });
        }if (Request::is('*/cliente/pasta/*')) {
            $router->bind('pasta', function ($id) {
                $pasta = $this->app->make('\Clientes\Cliente\Interfaces\PastaRepositoryInterface');
                return $pasta->findorNew($id);
            });
        }if (Request::is('*/cliente/endereco/*')) {
            $router->bind('endereco', function ($id) {
                $endereco = $this->app->make('\Clientes\Cliente\Interfaces\EnderecoRepositoryInterface');
                return $endereco->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';
        });
    }
}