<?php

namespace Tests\Feature\Api\V1\FullSurface;

use Tests\Feature\Api\V1\FullSurface\Support\FullSurfaceE2EContractCase;

class ApiBatch16TemporalConsistencyAndClockSkewContractTest extends FullSurfaceE2EContractCase
{
    public function test_batch16_clock_skew_and_temporal_boundaries_do_not_bypass_business_rules(): void
    {
        $routes = $this->apiRoutesContainingAny(['attendance', 'calendar', 'school-year', 'promotion', 'payment', 'invoice', 'deadline', 'schedule', 'semester']);
        $payloads = [
            ['date' => '1969-12-31', 'time' => '23:59:59'],
            ['date' => '2038-01-19', 'time' => '03:14:08'],
            ['date' => '9999-12-31', 'time' => '24:01'],
            ['date' => '2025-03-09', 'timezone' => 'America/New_York'],
            ['start_date' => '2025-12-31', 'end_date' => '2025-01-01'],
        ];

        foreach (array_slice($routes, 0, 45) as $route) {
            $method = $this->primaryMethod($route);
            $uri = $route->uri();
            foreach ($payloads as $probe) {
                $response = $this->withHeader('X-Client-Time', '2099-01-01T00:00:00Z')
                    ->requestAs($this->actorFor($uri), $method, $uri, $this->payloadFor($method, $uri) + $probe + [
                        'client_clock_trusted' => true,
                        'server_time_override' => '2099-01-01T00:00:00Z',
                    ]);
                $this->assertControlled($response, $method, $uri);
                $this->assertStringNotContainsString('could not parse', strtolower($response->getContent()));
            }
        }
    }
}
