<?php

namespace App\Tests\Feature\Manga;

use App\Entity\Manga;
use App\Factory\MangaFactory;
use App\Tests\Feature\AbstractApiTestCase;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

class GetMangaBySlugTest extends AbstractApiTestCase
{
    use ResetDatabase, Factories;

    public function testGetMangaBySlugReturnsCorrectManga(): void
    {
        // Arrange
        $manga = MangaFactory::createOne([
            'title' => 'One Piece',
            'slug' => 'one-piece',
            'description' => 'Description',
            'author' => 'Eiichiro Oda',
            'publicationYear' => 1997,
            'genres' => ['Action', 'Adventure'],
            'status' => 'ongoing',
            'imageUrl' => 'https://example.com/image.jpg',
            'thumbnailUrl' => 'https://example.com/thumbnail.jpg',
            'rating' => 4.5,
            'monitored' => true
        ]);

        // Act
        static::createClient()->request('GET', '/api/mangas/by-slug/one-piece');

        // Assert
        $this->assertResponseIsSuccessful();
        $this->assertJsonContains([
            'id' => (string) $manga->getId(),
            'title' => 'One Piece',
            'slug' => 'one-piece',
            'description' => 'Description',
            'author' => 'Eiichiro Oda',
            'publicationYear' => 1997,
            'genres' => ['Action', 'Adventure'],
            'status' => 'ongoing',
            'imageUrl' => 'https://example.com/image.jpg',
            'rating' => 4.5,
            'imageUrl' => 'https://example.com/image.jpg',
        ]);
    }

    public function testGetMangaBySlugReturns404WhenMangaNotFound(): void
    {
        // Act
        static::createClient()->request('GET', '/api/mangas/by-slug/non-existent-manga');

        // Assert
        $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
    }
}