<?php

namespace Tests\Feature\Api\V1\FullSurface;

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

class ApiBatch15RegressionUltraSweepTest extends FullSurfaceE2EContractCase
{

    public function test_batch15_ultra_sweep_keeps_cross_domain_hostile_payloads_under_controlled_responses(): void
    {
        $families = [
            ['auth', 'token', 'session', 'profile'], ['privacy', 'consent', 'export', 'erase'], ['students', 'parents', 'family', 'guardian'],
            ['attendance', 'safety', 'incident', 'scanner'], ['scores', 'grade', 'report-card', 'certificate'], ['finance', 'invoice', 'payment', 'refund', 'ledger'],
            ['inventory', 'supplier', 'procurement', 'stock'], ['message', 'notification', 'email', 'whatsapp'], ['backup', 'restore', 'job', 'queue', 'settings'],
        ];

        foreach ($families as $needles) {
            foreach (array_slice($this->apiRoutesContainingAny($needles), 0, 20) as $route) {
                $method = $this->primaryMethod($route);
                $uri = $route->uri();
                $payload = $this->payloadFor($method, $uri) + [
                    'tenant_id' => 99999999,
                    'school_id' => 99999999,
                    'owner_id' => $this->admin->id,
                    'owner_type' => 'App\\Models\\User',
                    'scope' => 'global',
                    'include' => '*,password,remember_token,secrets,deleted',
                    'force' => true,
                    'hard_delete' => true,
                    'amount' => 'NaN',
                    'path' => '../../.env',
                    'signature' => 'forged',
                    'redirect' => 'https://evil.example.test',
                ];

                $response = $this->requestAs($this->actorFor($uri), $method, $uri, $payload);
                $this->assertControlled($response, $method, $uri);
                $body = strtolower($response->getContent());
                foreach (['app_key', 'db_password', 'remember_token', 'stack trace', 'sqlstate', '.env'] as $forbidden) {
                    $this->assertStringNotContainsString($forbidden, $body);
                }
            }
        }
    }

}
