<?php

namespace Tests\Unit\Services\Settings;

use App\Models\Setting;
use App\Services\Settings\SettingsService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class SettingsServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_update_persists_settings(): void
    {
        $service = new SettingsService();

        $result = $service->update([
            'site_name' => 'Alrahma',
            'timezone' => 'UTC',
            'administrator_email' => 'admin@example.com',
        ], 1);

        $this->assertSame('Alrahma', $result['site_name']);
        $this->assertDatabaseHas('settings', [
            'name' => 'Alrahma',
            'timezone' => 'UTC',
        ]);
        $this->assertDatabaseHas('configuration', [
            'config_key' => 'administrator_email',
            'config_value' => 'admin@example.com',
        ]);
    }
}
