<?php

namespace Tests\Unit\Models;

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

class SettingTest extends TestCase
{
    use RefreshDatabase;

    public function test_get_article_publishing_interval_returns_default_when_not_set(): void
    {
        $this->assertSame(5, Setting::getArticlePublishingInterval());
    }

    public function test_get_article_publishing_interval_returns_stored_value(): void
    {
        Setting::set('article_publishing_interval', '10');

        $this->assertSame(10, Setting::getArticlePublishingInterval());
    }

    public function test_set_article_publishing_interval_persists_value(): void
    {
        Setting::setArticlePublishingInterval(15);

        $this->assertSame(15, Setting::getArticlePublishingInterval());
        $this->assertDatabaseHas('settings', [
            'key' => 'article_publishing_interval',
            'value' => '15',
        ]);
    }

    public function test_set_article_publishing_interval_zero(): void
    {
        Setting::setArticlePublishingInterval(0);

        $this->assertSame(0, Setting::getArticlePublishingInterval());
    }

    public function test_get_feed_staleness_threshold_returns_default_when_not_set(): void
    {
        $this->assertSame(48, Setting::getFeedStalenessThreshold());
    }

    public function test_get_feed_staleness_threshold_returns_stored_value(): void
    {
        Setting::set('feed_staleness_threshold', '72');

        $this->assertSame(72, Setting::getFeedStalenessThreshold());
    }

    public function test_set_feed_staleness_threshold_persists_value(): void
    {
        Setting::setFeedStalenessThreshold(24);

        $this->assertSame(24, Setting::getFeedStalenessThreshold());
        $this->assertDatabaseHas('settings', [
            'key' => 'feed_staleness_threshold',
            'value' => '24',
        ]);
    }

    public function test_set_feed_staleness_threshold_zero(): void
    {
        Setting::setFeedStalenessThreshold(0);

        $this->assertSame(0, Setting::getFeedStalenessThreshold());
    }
}
