<?php 
namespace Sargilla\FlatLab\Console;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;

/**
 * Class Publish FlatLab.
 */
class InstallFlatLab extends Command
{
    use Installable;
    /**
     * The filesystem instance.
     *
     * @var \Illuminate\Filesystem\Filesystem
     */
    protected $files;

    /**
     * The name and signature of the console command.
     */
    protected $signature = 'flatlab:install {--f|force : Force overwrite of files}';    

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Instalar los archivos necesarios para FlatLab en un proyecto laravel';

    /**
     * Force overwrite of files.
     *
     * @var bool
     */
    protected $force = false;

    /**
     * Create a new command instance.
     *
     * @param \Illuminate\Filesystem\Filesystem $files
     *
     */
    public function __construct(Filesystem $files)
    {
        parent::__construct();
        $this->files = $files;
    }

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $this->processOptions();
        $this->viewsToOverwrite();
        $this->publishPublicAssets();
        $this->publishResourceAssets();
        $this->publishHomeController();
        $this->changeRegisterController();
        $this->changeLoginController();
        $this->changeForgotPasswordController();
        $this->changeResetPasswordController();
        $this->changePasswordResetNotification();
        $this->changeUserModel();
        $this->changeUserMigration();
        $this->publishWebRoutes();
        $this->publishApiRoutes();
        $this->publishConfig();

    }
    /**
     * Publish FlatLab package config.
     */
    private function publishConfig()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::config());
    }
    /**
     *  Overwrite Views with FlatLab Views.
     */
    private function viewsToOverwrite()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::viewsToOverwrite());
    }

    /**
     * Install public assets.
     */
    private function publishPublicAssets()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::publicAssets());
    }

    /**
     * Install resource assets.
     */
    private function publishResourceAssets()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::resourceAssets());
    }

    /**
     * Change Auth Login controller.
     */
    private function changeLoginController()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::loginController());
    }
    
    /**
     * Install Home Controller.
     */
    private function publishHomeController()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::homeController());
    }

    /**
     * Change Auth Register controller.
     */
    private function changeRegisterController()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::registerController());
    }

    /**
     * Change Auth Forgot Password controller.
     */
    private function changeForgotPasswordController()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::forgotPasswordController());
    }

    /**
     * Change Auth Reset Password controller.
     */
    private function changeResetPasswordController()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::resetPasswordController());
    }

    /**
     * Change Auth Reset Password controller.
     */
    private function changePasswordResetNotification()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::PasswordResetNotification());
    }

    /**
     * Change Auth Reset Password controller.
     */
    private function changeUserModel()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::UserModel());
    }

    /**
     * Change Auth Reset Password controller.
     */
    private function changeUserMigration()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::UserMigration());
    }

    /**
     * Install resource assets.
     */
    private function publishTests()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::tests());
    }

    /**
     * Publish routes/web.php file.
     */
    private function publishWebRoutes()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::webroutes());
    }

    /**
     * Publish routes/api.php file.
     */
    private function publishApiRoutes()
    {
        $this->install(\Sargilla\FlatLab\Facades\FlatLab::apiroutes());
    }
    /**
     * Process options before running command.
     */
    private function processOptions()
    {
        $this->force = $this->option('force');
    }

}
