<?php

declare(strict_types=1);

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

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\Domain\Reader\Infrastructure\ApiPlatform\State\Provider\ChapterPagesProvider;
use Symfony\Component\Serializer\Annotation\Groups;

#[ApiResource(
    shortName: 'Reader',
    operations: [
        new Get(
            uriTemplate: '/reader/chapter/{chapterId}/pages',
            openapiContext: [
                'summary' => 'Récupère les pages d\'un chapitre',
                'description' => 'Retourne une collection paginée des pages du chapitre',
                'parameters' => [
                    [
                        'name' => 'chapterId',
                        'in' => 'path',
                        'required' => true,
                        'schema' => ['type' => 'string'],
                    ],
                    [
                        'name' => 'page',
                        'in' => 'query',
                        'required' => false,
                        'schema' => ['type' => 'integer', 'default' => 1],
                    ],
                    [
                        '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()
    {
    }
}
