<?php

namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaSearchCollection;
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider\SearchLocalMangaStateProvider;

#[ApiResource(
    shortName: 'MangaSearch',
    operations: [
        new GetCollection(
            uriTemplate: '/manga-search',
            provider: SearchLocalMangaStateProvider::class,
            output: MangaSearchCollection::class,
            status: 200,
            openapiContext: [
                'summary' => 'Recherche des mangas dans la bibliothèque locale',
                'description' => 'Recherche des mangas par titre, slug ou auteur (minimum 3 caractères)',
                'parameters' => [
                    [
                        'name' => 'q',
                        'in' => 'query',
                        'required' => true,
                        'schema' => [
                            'type' => 'string',
                            'minLength' => 3
                        ],
                        'description' => 'Terme de recherche (minimum 3 caractères)'
                    ],
                    [
                        'name' => 'page',
                        'in' => 'query',
                        'required' => false,
                        'schema' => [
                            'type' => 'integer',
                            'default' => 1,
                            'minimum' => 1
                        ],
                        'description' => 'Numéro de page'
                    ],
                    [
                        'name' => 'limit',
                        'in' => 'query',
                        'required' => false,
                        'schema' => [
                            'type' => 'integer',
                            'default' => 20,
                            'minimum' => 1,
                            'maximum' => 50
                        ],
                        'description' => 'Nombre de résultats par page'
                    ]
                ],
                'responses' => [
                    '200' => [
                        'description' => 'Résultats de la recherche',
                        'content' => [
                            'application/json' => [
                                'schema' => [
                                    'type' => 'object',
                                    'properties' => [
                                        'items' => [
                                            'type' => 'array',
                                            'items' => [
                                                '$ref' => '#/components/schemas/MangaSearchItem'
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ],
                    '400' => [
                        'description' => 'Paramètres de recherche invalides'
                    ]
                ]
            ]
        )
    ]
)]
class SearchLocalMangaResource
{
}
