<?php

declare(strict_types=1);

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

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\OpenApi\Model\Parameter;
use App\Domain\Reader\Infrastructure\ApiPlatform\State\Provider\ChapterPagesProvider;

#[ApiResource(
    shortName: 'Reader',
    operations: [
        new Get(
            uriTemplate: '/reader/chapter/{chapterId}/pages',
            openapi: new Operation(
                summary: 'Récupère les pages d\'un chapitre',
                description: 'Retourne une collection paginée des pages du chapitre',
                parameters: [
                    new Parameter(
                        name: 'chapterId',
                        in: 'path',
                        required: true,
                        schema: ['type' => 'string']
                    ),
                    new Parameter(
                        name: 'page',
                        in: 'query',
                        required: false,
                        schema: ['type' => 'integer', 'default' => 1]
                    ),
                    new Parameter(
                        name: 'itemsPerPage',
                        in: 'query',
                        required: false,
                        schema: ['type' => 'integer', 'default' => 20]
                    ),
                ],
                responses: [
                    '200' => [
                        'description' => 'Collection paginée des pages du chapitre',
                        'content' => [
                            'application/json' => [
                                'schema' => [
                                    'type' => 'object',
                                    'properties' => [
                                        'pages' => [
                                            'type' => 'array',
                                            'items' => [
                                                'type' => 'object',
                                                'properties' => [
                                                    'number' => ['type' => 'integer'],
                                                    'dimensions' => [
                                                        'type' => 'object',
                                                        'properties' => [
                                                            'width' => ['type' => 'integer'],
                                                            'height' => ['type' => 'integer'],
                                                        ],
                                                    ],
                                                ],
                                            ],
                                        ],
                                        'totalItems' => ['type' => 'integer'],
                                        'currentPage' => ['type' => 'integer'],
                                        'itemsPerPage' => ['type' => 'integer'],
                                        'totalPages' => ['type' => 'integer'],
                                    ],
                                ],
                            ],
                        ],
                    ],
                    '404' => [
                        'description' => 'Chapitre non trouvé',
                    ],
                ]
            ),
            provider: ChapterPagesProvider::class
        ),
    ],
)]
class ChapterPagesResource
{
    public function __construct()
    {
    }
}
