<?php

namespace Tests\Feature\Api\V1\FullSurface;

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


class ApiBatch18TemporalAuditAndTimezoneForgeryContractTest extends FullSurfaceE2EContractCase
{
    public function test_batch18_temporalauditandtimezoneforgery_stays_controlled(): void
    {
        $routes = $this->apiRoutesContainingAny(['attendance', 'finance', 'payments', 'refunds', 'audit', 'logs', 'reports', 'school-years', 'promotion']);
        $payload = [
            'created_at' => '1970-01-01T00:00:00Z',
            'updated_at' => '2099-12-31T23:59:59Z',
            'occurred_at' => '2099-12-31T23:59:59Z',
            'effective_at' => '1900-01-01T00:00:00Z',
            'timezone' => 'Etc/GMT+25',
            'client_timezone' => 'Mars/Olympus_Mons',
            'server_time' => '2099-12-31T23:59:59Z',
        ];

        foreach (array_slice($routes, 0, 100) as $route) {
            $method = $this->primaryMethod($route);
            $uri = $route->uri();
            $actor = $this->actorFor($uri);

            if (str_contains($uri, 'admin') || str_contains($uri, 'roles') || str_contains($uri, 'permissions')) {
                $actor = $this->studentUser;
            }

            $response = $this->requestAs($actor, $method, $uri, $this->payloadFor($method, $uri) + $payload);
            $this->assertControlled($response, $method, $uri);
            $this->assertNotEquals(500, $response->getStatusCode(), $method.' '.$uri.' crashed during Batch 18 temporal audit and timezone forgery probe.');

            $body = strtolower($response->getContent());
            foreach (['sqlstate', 'stack trace', 'app_key', 'remember_token', 'api_token', 'massassignmentexception', 'foreign key constraint'] as $leak) {
                $this->assertStringNotContainsString($leak, $body, $method.' '.$uri.' leaked '.$leak.' during Batch 18 temporal audit and timezone forgery probe.');
            }
        }
    }
}
