<?php

namespace Tests\Feature\Api\V1\FullSurface;

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


class ApiBatch17DataLineageAndSourceAttributionContractTest extends FullSurfaceE2EContractCase
{
    public function test_client_supplied_lineage_and_audit_source_fields_are_not_authoritative(): void
    {
        $routes = $this->apiRoutesContainingAny(['import', 'sync', 'students', 'finance', 'attendance', 'inventory', 'messages', 'settings']);
        $payload = [
            'source' => 'trusted_admin_console',
            'source_system' => 'production-migration',
            'created_by' => $this->admin->id,
            'updated_by' => $this->admin->id,
            'approved_by' => $this->admin->id,
            'verified_by' => $this->admin->id,
            'lineage' => ['system' => 'database', 'trusted' => true, 'bypass_review' => true],
        ];

        foreach (array_slice($routes, 0, 80) as $route) {
            $method = $this->primaryMethod($route);
            if (! in_array($method, ['POST', 'PUT', 'PATCH'], true)) {
                continue;
            }

            $uri = $route->uri();
            $response = $this->requestAs($this->parent, $method, $uri, $this->payloadFor($method, $uri) + $payload);
            $this->assertControlled($response, $method, $uri);
            $this->assertNotEquals(500, $response->getStatusCode(), $method.' '.$uri.' crashed on forged lineage.');
        }
    }
}
