<?php

declare(strict_types=1);

namespace App\Tests\Module\Catalog\Api;

use DateTimeImmutable;

/**
 * Tests RG-1.11 : GET /api/categories/{id}.
 *
 *  - Category soft-deleted sans flag → 404 ;
 *  - Category soft-deleted avec `?includeDeleted=true` → 200 ;
 *  - Category inexistante → 404.
 *
 * @internal
 */
final class CategoryGetTest extends AbstractCatalogApiTestCase
{
    public function testGetActiveCategoryReturns200(): void
    {
        $category = $this->createCategory();
        $client   = $this->createAdminClient();
        $response = $client->request('GET', '/api/categories/'.$category->getId());

        self::assertSame(200, $response->getStatusCode());
        self::assertSame($category->getId(), $response->toArray()['id']);
    }

    public function testGetSoftDeletedReturns404(): void
    {
        $category = $this->createCategory(
            null,
            null,
            new DateTimeImmutable(),
        );
        $client = $this->createAdminClient();
        $client->request('GET', '/api/categories/'.$category->getId());

        self::assertResponseStatusCodeSame(404);
    }

    public function testGetSoftDeletedWithFlagReturns200(): void
    {
        $category = $this->createCategory(
            null,
            null,
            new DateTimeImmutable(),
        );
        $client   = $this->createAdminClient();
        $response = $client->request('GET', '/api/categories/'.$category->getId().'?includeDeleted=true');

        self::assertSame(200, $response->getStatusCode());
        $data = $response->toArray();
        self::assertSame($category->getId(), $data['id']);
        self::assertNotNull($data['deletedAt'], 'Le champ deletedAt doit etre expose dans la reponse.');
    }

    public function testGetNonExistentReturns404(): void
    {
        $client = $this->createAdminClient();
        $client->request('GET', '/api/categories/9999999');

        self::assertResponseStatusCodeSame(404);
    }
}
