<?php

use App\Models\LotterySetting;
use App\Services\LotterySettings;
use Illuminate\Support\Facades\Cache;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

test('lottery settings get returns seeded value', function (): void {
    LotterySettings::put('fixture.flag', true, 'test', null);

    expect(LotterySettings::get('fixture.flag'))->toBeTrue();
});

test('env locked draw settings ignore database overrides', function (): void {
    config(['lottery.draw.interval_minutes' => 9]);
    LotterySettings::put('draw.interval_minutes', 99, 'draw');

    expect(LotterySettings::drawIntervalMinutes())->toBe(9);
});

test('lottery settings misses are not cached', function (): void {
    Cache::flush();

    expect(LotterySettings::get('not.exists', 'fallback'))->toBe('fallback');

    LotterySetting::query()->create([
        'setting_key' => 'not.exists',
        'value_json' => 'hello',
        'group_name' => 'test',
    ]);

    LotterySettings::forgetKey('not.exists');

    expect(LotterySettings::get('not.exists'))->toBe('hello');
});
