<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class MakeServiceCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'make:service {name : fileName}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create Service file';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        if (!file_exists(base_path('app\\Services'))){
            mkdir('app\\Services',666,false);
        }
        $fileName=$this->argument('name');
        if (!file_exists(base_path('app\\Services\\'.$fileName.'.php'))){
            file_put_contents(base_path('app\\Services\\'.$fileName.'.php'),
                '<?php '.PHP_EOL.PHP_EOL.'namespace App\Services; '.PHP_EOL.PHP_EOL.'Class '.$fileName.PHP_EOL.'{ '.PHP_EOL.PHP_EOL.PHP_EOL.'}');
        }
        else $this->error("ERROR: file exists;");
    }
}
