<?php

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

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

#[ApiResource(
    shortName: 'Mangadex',
    operations: [
        new Post(
            uriTemplate: '/mangas/create-from-mangadex',
            processor: CreateMangaProcessor::class,
            openapiContext: [
                'summary' => 'Create a new manga from Mangadex',
                'description' => 'Creates a new manga by fetching its data from Mangadex using an external ID',
                'requestBody' => [
                    'content' => [
                        'application/json' => [
                            'schema' => [
                                'type' => 'object',
                                'required' => ['externalId'],
                                'properties' => [
                                    'externalId' => [
                                        'type' => 'string',
                                        'description' => 'The Mangadex ID of the manga'
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        )
    ]
)]
class CreateMangaResource
{
    #[Assert\NotBlank]
    public string $externalId;
}
