<?php

namespace Tests\Unit\Services\System;

use App\Services\System\ConfigUpdateService;
use DateTimeZone;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ConfigUpdateServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_run_task_rejects_unknown_task(): void
    {
        $service = new ConfigUpdateService();
        $result = $service->runTask('unknown', false, false, new DateTimeZone('UTC'));

        $this->assertFalse($result['ok']);
    }

    public function test_run_task_sets_config_when_forced(): void
    {
        $service = new ConfigUpdateService();
        $result = $service->runTask('enable_attendance_on', false, true, new DateTimeZone('UTC'));

        $this->assertTrue($result['ok']);
        $this->assertDatabaseHas('configuration', [
            'config_key' => 'enable_attendance',
            'config_value' => '1',
        ]);
    }
}
