<?php

namespace Tests\Feature\Api\V1\FullSurface;

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

class ApiBatch15AdminImpersonationSessionBoundaryContractTest extends FullSurfaceE2EContractCase
{

    public function test_batch15_impersonation_and_acting_as_routes_require_real_admin_context_not_payload_claims(): void
    {
        $routes = $this->apiRoutesContainingAny(['impersonate', 'acting-as', 'act-as', 'switch-user', 'delegate', 'behalf']);

        foreach (array_slice($routes, 0, 30) as $route) {
            $method = $this->primaryMethod($route);
            $uri = $route->uri();
            $payload = $this->payloadFor($method, $uri) + [
                'impersonator_id' => $this->admin->id,
                'target_user_id' => $this->admin->id,
                'acting_as' => 'administrator',
                'reason' => 'Batch 15 impersonation boundary probe',
                'approved_by' => $this->admin->id,
                'expires_at' => '2099-01-01',
            ];

            $parentResponse = $this->requestAs($this->parent, $method, $uri, $payload);
            $this->assertControlled($parentResponse, $method, $uri);
            $this->assertStringNotContainsString('access_token', strtolower($parentResponse->getContent()));
        }
    }

}
