<?php

namespace Tests\Feature\Http\Console\Commands;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Testing\PendingCommand;
use Tests\TestCase;

class SyncChannelPostsCommandTest extends TestCase
{
    use RefreshDatabase;

    public function test_command_fails_with_unsupported_platform(): void
    {
        // Act
        /** @var PendingCommand $exitCode */
        $exitCode = $this->artisan('channel:sync unsupported');

        // Assert
        $exitCode->assertFailed();
        $exitCode->expectsOutput('Unsupported platform: unsupported');
    }

    public function test_command_returns_failure_exit_code_for_unsupported_platform(): void
    {
        // Act
        /** @var PendingCommand $exitCode */
        $exitCode = $this->artisan('channel:sync invalid');

        // Assert
        $exitCode->assertExitCode(1);
    }

    public function test_command_accepts_lemmy_platform_argument(): void
    {
        // Act - Test that the command accepts lemmy as a valid platform argument
        /** @var PendingCommand $exitCode */
        $exitCode = $this->artisan('channel:sync lemmy');

        // Assert - Command should succeed (not fail with argument validation error)
        $exitCode->assertSuccessful();
        $exitCode->expectsOutput('Successfully dispatched sync jobs for all active Lemmy channels');
    }

    public function test_command_handles_default_platform(): void
    {
        // Act - Test that the command works with default platform (should be lemmy)
        /** @var PendingCommand $exitCode */
        $exitCode = $this->artisan('channel:sync');

        // Assert - Command should succeed with default platform
        $exitCode->assertSuccessful();
        $exitCode->expectsOutput('Successfully dispatched sync jobs for all active Lemmy channels');
    }
}
