<?php

namespace App\Console\Commands;

use App\Services\ObsWsClient;
use Illuminate\Console\Command;
use Throwable;

class RigCmdCommand extends Command
{
    protected $signature = 'rig:cmd {type : skip|prev|pause|resume}';
    protected $description = 'Broadcast a music daemon command over OBS WS (CLI mirror of POST /cmd/{type})';

    public function handle(ObsWsClient $ws): int
    {
        $type = strtolower((string) $this->argument('type'));
        if (!in_array($type, ['skip', 'prev', 'pause', 'resume'], true)) {
            $this->error('type must be one of: skip, prev, pause, resume');
            return self::FAILURE;
        }
        try {
            $ws->broadcast('mpd:cmd', ['type' => $type]);
        } catch (Throwable $e) {
            $this->error($e->getMessage());
            return self::FAILURE;
        }
        $this->info("  → {$type}");
        return self::SUCCESS;
    }
}
