<?php

use App\Services\Calendar\CalendarRangeResolver;
use Carbon\Carbon;
use Illuminate\Http\Request;

test('safeDate falls back to default on invalid date', function () {
    $resolver = new CalendarRangeResolver();
    $tz = 'America/New_York';

    $date = $resolver->safeDate('nope', $tz, '2026-02-04');

    expect($date->toDateString())->toBe('2026-02-04');
});

test('resolveRange handles four-day view', function () {
    $resolver = new CalendarRangeResolver();
    $tz = 'America/New_York';

    $request = Request::create('/calendar', 'GET', [
        'view' => 'four',
        'date' => '2026-02-04',
    ]);

    [$view, $range] = $resolver->resolveRange(
        $request,
        $tz,
        Carbon::SUNDAY,
        Carbon::SATURDAY,
        'month',
        '2026-02-04'
    );

    expect($view)->toBe('four');
    expect($range['start']->toDateString())->toBe('2026-02-04');
    expect($range['end']->toDateString())->toBe('2026-02-07');
});
