<?php

namespace Tests\Feature\Api;

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

class MarkOfflineDevicesTest extends TestCase
{
    use RefreshDatabase;

    public function test_flips_devices_offline_after_threshold(): void
    {
        $alive = Device::create(['name' => 'A', 'hostname' => 'A', 'device_token_hash' => str_repeat('a', 64), 'online' => true, 'last_seen_at' => now()->subSeconds(10)]);
        $stale = Device::create(['name' => 'B', 'hostname' => 'B', 'device_token_hash' => str_repeat('b', 64), 'online' => true, 'last_seen_at' => now()->subMinutes(2)]);

        $this->artisan('devices:mark-offline')->assertSuccessful();

        $this->assertTrue($alive->fresh()->online);
        $this->assertFalse($stale->fresh()->online);
    }
}
