<?php namespace Support;

use Request;
use Illuminate\Support\ServiceProvider;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Auth\Guard;
use Illuminate\Hashing\BcryptHasher;
use Illuminate\Auth\Reminders\PasswordBroker;
use Illuminate\Auth\Reminders\DatabaseReminderRepository;
use \Support\BandGuard;
use \Support\BandAuth;

class BandAuthServiceProvider extends ServiceProvider
{

    public function register()
    {
        $this->registerAuth();
        //$this->registerReminders();
    }

    protected function registerAuth()
    {
        $this->registerBandCrypt();
        $this->registerBandProvider();
        $this->registerBandGuard();
    }

    protected function registerBandCrypt()
    {
        $this->app['band.auth.crypt'] = $this->app->share(function($app)
        {
            return new BcryptHasher;
        });
    }

    protected function registerBandProvider()
    {
        $this->app['band.auth.provider'] = $this->app->share(function($app)
        {
            return new EloquentUserProvider(
                $app['band.auth.crypt'],
                'Band'
            );
        });
    }

    protected function registerBandGuard()
    {
        $this->app['band.auth'] = $this->app->share(function($app)
        {
            $guard = new BandGuard(
                $app['band.auth.provider'],
                $app['session.store'],
                Request::instance()
            );

            $guard->setCookieJar($app['cookie']);
            return $guard;
        });
    }

    public function provides()
    {
        return array(
            'band.auth',
            'band.auth.provider',
            'band.auth.crypt',
        );
    }
}
