<?php

namespace App\Modules\Core\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

class ModuleMakeModel extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'module:model {module} {model}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new model for a module';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        $moduleName = $this->argument('module');
        $modelName = $this->argument('model');
        $modulePath = modules_path($moduleName);

        if (! is_dir($modulePath)) {
            $this->error("Module [{$moduleName}] does not exist.");

            return;
        }

        $modelPath = "App\\Modules\\{$moduleName}\\Models\\{$modelName}";

        Artisan::call('make:model', [
            'name' => $modelPath,
        ]);

        $this->info("Model [{$modelName}] created successfully in module [{$moduleName}].");
    }
}
