<?php

namespace Overdrive\Web\Commands;

use Illuminate\Console\Command;
use Overdrive\Web\Commands\AuthAssetCommand;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Artisan;

class AuthAssetCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'overide:asset';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a symbolic link from "public/overide" to "web/asset"';

    /**
     * Execute the console command.
     *
     * @return mixed
     */


    public function handle()
    {
        if (!file_exists(public_path('overide/web'))) {
            
            mkdir(public_path('overide'));
            mkdir(public_path('overide/web'));
        }

        if (!file_exists(public_path('overide/web/themes'))) {
            $this->laravel->make('files')->link(
                \Web\web_path('vendor'),
                public_path('overide/web/themes')
            );
        }

        $this->info('The [public/overide/web/themes] directory has been linked.');

        $this->publishConfiguration($force = true);


        $this->info('The routing  auth file has being ovveriden.');

    }

    private function publishConfiguration($forcePublish = false)
    {
        $params = [
            '--provider' => "Overdrive\Web\ServiceProvider",
            '--tag' => "overdrive-route"
        ];

        if ($forcePublish === true) {
            $params['--force'] = true;
        }

       $this->call('vendor:publish', $params);
    }
}
