<?php

require_once __DIR__ . '/SegmentSeatAvailabilityBootstrap.php';

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

/**
 * Trip 75-style overnight overlap: 11:30 PM → 04:00 AM vs 01:15 AM → 07:30 AM.
 *
 * @internal
 */
final class SegmentRouteTimelineOverlapTest extends TestCase
{
    /** @var list<string> */
    private array $stops = ['32', '41', '43', '54', '66', '67', '77', '78', '90', '55'];

    public function testCityOnlySegmentMissesPartialOverlap(): void
    {
        // Stored ticket cities: Cairo→Sharm (32→41) vs search Ras Sudr→El Tor (54→43) — no city overlap.
        $this->assertFalse(SegmentSeatAvailability::segmentsOverlap(
            $this->stops,
            '54',
            '43',
            '32',
            '41'
        ));
    }

    public function testCitySegmentDetectsNestedOverlap(): void
    {
        $this->assertTrue(SegmentSeatAvailability::segmentsOverlap(
            $this->stops,
            '32',
            '41',
            '32',
            '54'
        ));
    }

    public function testHandoffAtSameStopNoOverlap(): void
    {
        $this->assertFalse(SegmentSeatAvailability::segmentsOverlap(
            $this->stops,
            '41',
            '54',
            '32',
            '41'
        ));
    }
}
