<?php

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

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use App\Domain\Manga\Infrastructure\ApiPlatform\Controller\ImportChapterController;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
    shortName: 'ImportChapter',
    operations: [
        new Post(
            uriTemplate: '/chapters/import',
            controller: ImportChapterController::class,
            deserialize: false,
            openapiContext: [
                'summary' => 'Import a chapter from CBZ file',
                'description' => 'Imports a CBZ file for an existing chapter and stores it',
                'requestBody' => [
                    'content' => [
                        'multipart/form-data' => [
                            'schema' => [
                                'type' => 'object',
                                'required' => ['mangaId', 'chapterNumber', 'file'],
                                'properties' => [
                                    'mangaId' => [
                                        'type' => 'string',
                                        'format' => 'uuid',
                                        'description' => 'The manga UUID'
                                    ],
                                    'chapterNumber' => [
                                        'type' => 'number',
                                        'description' => 'The chapter number (e.g., 1.5)'
                                    ],
                                    'file' => [
                                        'type' => 'string',
                                        'format' => 'binary',
                                        'description' => 'CBZ file to import (max 500MB)'
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],
                'responses' => [
                    '200' => [
                        'description' => 'Chapter imported successfully',
                        'content' => [
                            'application/json' => [
                                'schema' => [
                                    'type' => 'object',
                                    'properties' => [
                                        'message' => ['type' => 'string'],
                                        'chapterId' => ['type' => 'string']
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        )
    ]
)]
class ImportChapterResource
{
    public ?string $mangaId = null;

    public ?float $chapterNumber = null;

    public ?File $file = null;
}
