<?php
namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Services\MigrationService;

class MigrateMaster extends Command
{
    protected $signature = 'migrate:master {--rollback} {--step=1}';
    protected $description = 'Run migrations on master database only';

    public function handle(MigrationService $migrationService)
    {
        if ($this->option('rollback')) {
            $result = $migrationService->rollbackMasterMigrations($this->option('step'));
            $this->info($result['message']);
            $this->line($result['output']);
        } else {
            $result = $migrationService->runMasterMigrations();
            $this->info($result['message']);
            if (!empty($result['migrations'])) {
                $this->table(['Master Migrations'], array_map(fn($m) => [$m], $result['migrations']));
            }
        }
    }
}
