<?php

require_once __DIR__ . '/SegmentSeatAvailabilityBootstrap.php';

use App\Libraries\TripJourneyDateHelper;
use PHPUnit\Framework\TestCase;

final class TripJourneyDateHelperStorageTest extends TestCase
{
    public function testDisplayReturnsStoredDateWhenTripUnknown(): void
    {
        $helper = new TripJourneyDateHelper();

        $this->assertSame(
            '2026-07-20',
            $helper->getPassengerBoardingDateForDisplay(0, 0, '2026-07-20', 0)
        );
    }

    public function testJourneyListSearchMatchesBusStartOnly(): void
    {
        $helper = new TripJourneyDateHelper();

        $this->assertTrue($helper->rowMatchesJourneyListSearchDate('2026-07-20', '2026-07-21', '2026-07-20'));
        $this->assertFalse($helper->rowMatchesJourneyListSearchDate('2026-07-20', '2026-07-21', '2026-07-21'));
    }

    public function testManifestSearchPrefetchesAdjacentDays(): void
    {
        $helper = new TripJourneyDateHelper();

        $this->assertSame(
            ['2026-07-20', '2026-07-19', '2026-07-21'],
            $helper->getBusStartDatesForBoardingSearch('2026-07-20')
        );
    }

    public function testResolveManifestFromJourneyListRowWithoutTripContextReturnsStored(): void
    {
        $helper = new TripJourneyDateHelper();

        $this->assertSame(
            '2026-07-21',
            $helper->resolveManifestDateFromJourneyListRow(0, 0, '2026-07-21', 0)
        );
    }

    public function testTicketSearchIncludesAdjacentDaysForLegacyRows(): void
    {
        $helper = new TripJourneyDateHelper();

        $this->assertSame(
            ['2026-07-20', '2026-07-19', '2026-07-21'],
            $helper->getTicketSearchMatchDates('2026-07-20')
        );
    }

}
