<?php

namespace Dipper\JWTAuth;

use Tymon\JWTAuth\Http\Parser\Cookies;
use Tymon\JWTAuth\Http\Middleware\Check;
use Tymon\JWTAuth\Http\Parser\AuthHeaders;
use Tymon\JWTAuth\Http\Parser\InputSource;
use Illuminate\Contracts\Auth\UserProvider;
use Tymon\JWTAuth\Http\Middleware\Authenticate;
use Tymon\JWTAuth\Http\Middleware\RefreshToken;
use Tymon\JWTAuth\Http\Middleware\AuthenticateAndRenew;
use Tymon\JWTAuth\Providers\AbstractServiceProvider as JWTServiceProvider;

class JWTAuthServiceProvider extends JWTServiceProvider
{
    /**
     * Register any application services.
     * @return void
     */
    public function register()
    {
        parent::register();
    }

    /**
     * Boot the service provider.
     *
     * @return void
     */
    public function boot()
    {
        $this->app['auth']->provider('service', function ($app, array $config) {
            $class = '\\'.ltrim($config['name'], '\\');

            if (class_implements($class)[UserProvider::class]) {
                return $app->make($class);
            }
            
            return new ServiceUserProvider($app->make($class));
        });

        $this->app->configure('jwt');

        $this->extendAuthGuard();

        $this->app['tymon.jwt.parser']->setChain([
            AuthHeaders::class => new AuthHeaders,
            InputSource::class => (new InputSource)->setKey('access_token'),
        ]);
    }
}
