<?php

namespace App\Console\Commands;

use App\Jobs\SyncChannelPostsJob;
use Illuminate\Console\Command;

class SyncChannelPostsCommand extends Command
{
    protected $signature = 'channel:sync {platform=lemmy}';

    protected $description = 'Manually sync channel posts for a platform';

    public function handle(): int
    {
        $platform = $this->argument('platform');

        if ($platform === 'lemmy') {
            return $this->syncLemmy();
        }

        $this->error("Unsupported platform: {$platform}");

        return self::FAILURE;
    }

    private function syncLemmy(): int
    {
        SyncChannelPostsJob::dispatchForAllActiveChannels();
        $this->info('Successfully dispatched sync jobs for all active Lemmy channels');

        return self::SUCCESS;
    }
}
