<?php

namespace Tests\Feature;

use App\Models\BannedIp;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class UnbanCommandTest extends TestCase
{
    use RefreshDatabase;

    public function test_unban_single_ip(): void
    {
        BannedIp::create(['ip' => '203.0.113.5', 'banned_until' => now()->addHour(), 'attempts' => 10]);
        $this->artisan('clusev:unban', ['ip' => '203.0.113.5'])->assertSuccessful();
        $this->assertDatabaseCount('banned_ips', 0);
    }

    public function test_unban_all(): void
    {
        BannedIp::create(['ip' => '203.0.113.5', 'banned_until' => now()->addHour(), 'attempts' => 10]);
        BannedIp::create(['ip' => '203.0.113.6', 'banned_until' => now()->addHour(), 'attempts' => 10]);
        $this->artisan('clusev:unban', ['--all' => true])->assertSuccessful();
        $this->assertDatabaseCount('banned_ips', 0);
    }

    public function test_unban_without_args_fails(): void
    {
        $this->artisan('clusev:unban')->assertFailed();
    }
}
