<?php

namespace Tests\Feature\Api\V1\FullSurface;

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

class ApiBatch15CrossSchoolIdentityCollisionContractTest extends FullSurfaceE2EContractCase
{

    public function test_batch15_duplicate_external_identifiers_and_cross_school_aliases_fail_cleanly(): void
    {
        $routes = $this->apiRoutesContainingAny(['students', 'users', 'parents', 'family', 'guardian', 'enrollment', 'registration']);

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

            $payload = $this->payloadFor($method, $route->uri()) + [
                'external_id' => 'SHARED-EXTERNAL-ID',
                'student_number' => 'SHARED-STUDENT-NUMBER',
                'email' => $this->admin->email,
                'phone' => '+15550000000',
                'school_id' => 99999999,
                'tenant_id' => 99999999,
            ];

            $response = $this->requestAs($this->admin, $method, $route->uri(), $payload);
            $this->assertControlled($response, $method, $route->uri());
            $this->assertStringNotContainsString('duplicate entry', strtolower($response->getContent()));
        }
    }

}
