<?php

namespace File\File\Providers;

use Illuminate\Support\ServiceProvider;

class FileServiceProvider 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', 'file');

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

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

    }

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

// Bind Image to repository
        $this->app->bind(
            \File\File\Interfaces\ImageRepositoryInterface::class,
            \File\File\Repositories\Eloquent\ImageRepository::class
        );        // Bind Video to repository
        $this->app->bind(
            \File\File\Interfaces\VideoRepositoryInterface::class,
            \File\File\Repositories\Eloquent\VideoRepository::class
        );        // Bind Auteur to repository
        $this->app->bind(
            \File\File\Interfaces\AuteurRepositoryInterface::class,
            \File\File\Repositories\Eloquent\AuteurRepository::class
        );

        $this->app->register(\File\File\Providers\AuthServiceProvider::class);
        $this->app->register(\File\File\Providers\EventServiceProvider::class);
        $this->app->register(\File\File\Providers\RouteServiceProvider::class);
        // $this->app->register(\File\File\Providers\WorkflowServiceProvider::class);
    }

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

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

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

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

        // Publish migrations
        $this->publishes([__DIR__ . '/../../../../database/migrations/' => base_path('database/migrations')], 'migrations');

        // Publish seeds
        $this->publishes([__DIR__ . '/../../../../database/seeds/' => base_path('database/seeds')], 'seeds');

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