<?php

namespace Tests\Unit;

use App\Helpers\SystemHealthHelper;
use App\Models\FingerprintMachine;

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

class SystemHealthHelperTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed();
    }

    public function test_check_database_connection_returns_healthy(): void
    {
        $dbStatus = SystemHealthHelper::checkDatabaseConnection();

        $this->assertEquals('healthy', $dbStatus['status']);
        $this->assertEquals('Terhubung', $dbStatus['label']);
        $this->assertArrayHasKey('latency_ms', $dbStatus);
    }

    public function test_check_cronjob_status_returns_array(): void
    {
        $cronStatus = SystemHealthHelper::checkCronjobStatus();

        $this->assertArrayHasKey('status', $cronStatus);
        $this->assertArrayHasKey('label', $cronStatus);
    }

    public function test_machine_socket_latency_test(): void
    {
        $machine = FingerprintMachine::first();
        $this->assertNotNull($machine);

        $result = SystemHealthHelper::testMachineSocketLatency($machine);

        $this->assertArrayHasKey('status', $result);
        $this->assertArrayHasKey('latency_ms', $result);
    }
}
