<?php

declare(strict_types=1);

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class CreateBaseCommand extends Command
{
    protected $signature = 'make:model-request {model} {--pivot}';

    protected $description = 'Create a model and its corresponding request class';

    protected $pivot = false;

    public function handle()
    {
        $modelName = $this->argument('model');
        $pivot = $this->option('pivot');
        $this->pivot = $pivot;

        if ($this->pivot) {
            $this->call('make:migration', [
                'name' => 'create_model_has' . Str::plural($modelName) . '_table',
            ]);
        } else {
            $this->call('make:request', [
                'name' => Str::singular($modelName) . 'Request',
            ]);

            $this->call('make:model', [
                'name' => Str::singular($modelName),
                '-c' => true,
                '-m' => true,
                '--policy' => true,
                '-r' => true,
            ]);

            $this->call('make:resource', [
                'name' => Str::singular($modelName) . 'Resource',
            ]);
        }
    }
}
