<?php

namespace Tests\Unit\Services\Security;

use App\Services\Security\IpBanQueryService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class IpBanQueryServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_paginate_filters_active(): void
    {
        DB::table('ip_attempts')->insert([
            [
                'ip_address' => '10.0.0.1',
                'attempts' => 2,
                'blocked_until' => now('UTC')->addHours(2),
            ],
            [
                'ip_address' => '10.0.0.2',
                'attempts' => 2,
                'blocked_until' => now('UTC')->subHours(1),
            ],
        ]);

        $service = app(IpBanQueryService::class);
        $pager = $service->paginate(['status' => 'active'], 1, 10);

        $this->assertSame(1, $pager->total());
        $this->assertSame('10.0.0.1', $pager->items()[0]->ip_address);
    }
}
