<?php

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

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\EditMultipleChaptersProcessor;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
    shortName: 'Chapters',
    operations: [
        new Post(
            uriTemplate: '/chapters/batch-edit',
            processor: EditMultipleChaptersProcessor::class,
            input: EditMultipleChaptersResource::class,
            status: 200,
            openapiContext: [
                'summary' => 'Edit multiple chapters',
                'description' => 'Updates title and/or volume for multiple chapters in a single request'
            ]
        )
    ]
)]
class EditMultipleChaptersResource
{
    public function __construct(
        #[Assert\NotBlank(message: 'La liste des chapitres est obligatoire')]
        #[Assert\Count(min: 1, minMessage: 'Vous devez spécifier au moins un chapitre')]
        public readonly array $chapters
    ) {
    }
}

readonly class ChapterEditData
{
    public function __construct(
        public string $id,
        public ?string $title = null,
        public ?int $volume = null
    ) {
    }
}
