<?php

declare(strict_types=1);

use App\Services\DaData\DaDataBudgetGuard;

it('allows spend while under the daily cap', function (): void {
    config(['services.dadata.daily_cap_rub' => 10]); // 1000 копеек
    $guard = app(DaDataBudgetGuard::class);

    expect($guard->canSpend())->toBeTrue();

    $guard->recordSpend(500);

    expect($guard->canSpend())->toBeTrue()
        ->and($guard->spentTodayKopecks())->toBe(500);
});

it('blocks spend once the daily cap is reached', function (): void {
    config(['services.dadata.daily_cap_rub' => 1]); // 100 копеек
    $guard = app(DaDataBudgetGuard::class);

    $guard->recordSpend(100);

    expect($guard->canSpend())->toBeFalse();
});

it('accumulates spend across multiple calls', function (): void {
    config(['services.dadata.daily_cap_rub' => 100]);
    $guard = app(DaDataBudgetGuard::class);

    $guard->recordSpend(30);
    $guard->recordSpend(70);

    expect($guard->spentTodayKopecks())->toBe(100);
});

it('starts at zero spend for a fresh day', function (): void {
    $guard = app(DaDataBudgetGuard::class);

    expect($guard->spentTodayKopecks())->toBe(0);
});
