<?php

declare(strict_types=1);

use App\Services\Intune\TenantRequiredPermissionsViewModelBuilder;
use Carbon\CarbonImmutable;

it('marks freshness as stale when last refreshed is missing', function (): void {
    $freshness = TenantRequiredPermissionsViewModelBuilder::deriveFreshness(
        null,
        CarbonImmutable::parse('2026-02-08 12:00:00'),
    );

    expect($freshness['last_refreshed_at'])->toBeNull()
        ->and($freshness['is_stale'])->toBeTrue();
});

it('marks freshness as stale when last refreshed is older than 30 days', function (): void {
    $freshness = TenantRequiredPermissionsViewModelBuilder::deriveFreshness(
        CarbonImmutable::parse('2026-01-08 11:59:59'),
        CarbonImmutable::parse('2026-02-08 12:00:00'),
    );

    expect($freshness['is_stale'])->toBeTrue();
});

it('marks freshness as not stale when last refreshed is exactly 30 days old', function (): void {
    $freshness = TenantRequiredPermissionsViewModelBuilder::deriveFreshness(
        CarbonImmutable::parse('2026-01-09 12:00:00'),
        CarbonImmutable::parse('2026-02-08 12:00:00'),
    );

    expect($freshness['is_stale'])->toBeFalse();
});
