<?php

namespace Tests\Concerns;

use Illuminate\Testing\TestResponse;

trait AssertsE2EApiResponses
{
    protected function assertNoServerError(TestResponse $response, string $context): void
    {
        $this->assertLessThan(
            500,
            $response->getStatusCode(),
            $context . ' should return a controlled response, not a 5xx crash. Body: ' . $response->getContent()
        );
    }

    /**
     * @param array<int, int> $statuses
     */
    protected function assertStatusIn(TestResponse $response, array $statuses, string $context): void
    {
        $this->assertContains(
            $response->getStatusCode(),
            $statuses,
            $context . ' returned unexpected status ' . $response->getStatusCode() . '. Body: ' . $response->getContent()
        );
    }

    protected function assertSuccessfulOrValidation(TestResponse $response, string $context): void
    {
        $this->assertStatusIn($response, [200, 201, 202, 204, 302, 409, 422], $context);
    }
}
