<?php

namespace Futage\Show\Providers;

use Illuminate\Support\ServiceProvider;

class ShowServiceProvider extends ServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        // Load view
        $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'show');

        // Load translation
        $this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'show');

        // Load migrations
        $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');

        // Call pblish redources function
        $this->publishResources();

    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        // Bind facade
        $this->app->bind('futage.show', function ($app) {
            return $this->app->make('Futage\Show\Show');
        });

        // Bind Show to repository
        $this->app->bind(
            'Futage\Show\Interfaces\ShowRepositoryInterface',
            \Futage\Show\Repositories\Eloquent\ShowRepository::class
        );        // Bind Episode to repository
        $this->app->bind(
            'Futage\Show\Interfaces\EpisodeRepositoryInterface',
            \Futage\Show\Repositories\Eloquent\EpisodeRepository::class
        );

        $this->app->register(\Futage\Show\Providers\AuthServiceProvider::class);
        
        $this->app->register(\Futage\Show\Providers\RouteServiceProvider::class);
                
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return ['futage.show'];
    }

    /**
     * Publish resources.
     *
     * @return void
     */
    private function publishResources()
    {
        // Publish configuration file
        $this->publishes([__DIR__ . '/../../config/config.php' => config_path('futage/show.php')], 'config');

        // Publish admin view
        $this->publishes([__DIR__ . '/../../resources/views' => base_path('resources/views/vendor/show')], 'view');

        // Publish language files
        $this->publishes([__DIR__ . '/../../resources/lang' => base_path('resources/lang/vendor/show')], 'lang');

        // Publish public files and assets.
        $this->publishes([__DIR__ . '/public/' => public_path('/')], 'public');
    }
}