<?php

namespace Tests\Feature\Api\V1\FullSurface;

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

class ApiBatch16EmergencyContactAndPickupSafetyContractTest extends FullSurfaceE2EContractCase
{
    public function test_batch16_pickup_guardian_and_emergency_contact_routes_reject_wrong_family_and_expired_delegations(): void
    {
        $routes = $this->apiRoutesContainingAny(['emergency', 'guardian', 'authorized', 'pickup', 'family', 'whatsapp']);

        foreach (array_slice($routes, 0, 45) as $route) {
            $method = $this->primaryMethod($route);
            $uri = $route->uri();
            $response = $this->requestAs($this->parent, $method, $uri, $this->payloadFor($method, $uri) + [
                'family_id' => 999999,
                'student_id' => 999999,
                'authorized_user_id' => 999999,
                'guardian_id' => 999999,
                'pickup_allowed' => true,
                'expires_at' => '1990-01-01',
                'verified_by_admin' => true,
            ]);

            $this->assertControlled($response, $method, $uri);
            $this->assertStringNotContainsString('foreign key constraint fails', strtolower($response->getContent()));
        }
    }
}
