<?php

namespace Tests\Feature\Api\V1\FullSurface;

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

class ApiNullBooleanAndTypeCoercionContractTest extends FullSurfaceE2EContractCase
{
    public function test_mutation_routes_handle_null_false_zero_and_string_booleans_without_crashing(): void
    {
        $routes = array_slice(array_filter($this->apiRoutes(), fn ($route) => in_array($this->primaryMethod($route), ['POST', 'PUT', 'PATCH'], true)), 0, 150);

        foreach ($routes as $route) {
            $method = $this->primaryMethod($route);
            $uri = $route->uri();
            $payload = $this->payloadFor($method, $uri) + [
                'active' => 'false',
                'enabled' => '0',
                'is_primary' => null,
                'notify_parent' => false,
                'amount' => '000000.00',
                'student_id' => '0',
                'class_section_id' => false,
            ];

            $response = $this->requestAs($this->actorFor($uri), $method, $uri, $payload);

            $this->assertControlled($response, $method, $uri);
            $this->assertNoServerError($response, 'type coercion probe at ' . $method . ' ' . $uri);
        }
    }
}
