<?php

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

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\RequestBody;
use App\Domain\Scraping\Infrastructure\ApiPlatform\State\Processor\SetMangaPreferredSourcesStateProcessor;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
    shortName: 'Scraping',
    operations: [
        new Post(
            uriTemplate: '/mangas/{id}/preferred-sources',
            processor: SetMangaPreferredSourcesStateProcessor::class,
            status: 200,
            description: 'Définir les sources préférées d\'un manga dans l\'ordre de priorité',
            openapi: new OpenApiOperation(
                summary: 'Configurer les sources préférées d\'un manga',
                description: 'Définit l\'ordre de priorité des sources de scraping pour un manga. Format attendu: {"sourceIds": ["source1", "source2"]}',
                requestBody: new RequestBody(
                    content: new \ArrayObject([
                        'application/json' => [
                            'schema' => [
                                'type' => 'object',
                                'properties' => [
                                    'sourceIds' => [
                                        'type' => 'array',
                                        'items' => ['type' => 'string']
                                    ]
                                ]
                            ],
                            'example' => [
                                'sourceIds' => ['1', '2']
                            ]
                        ]
                    ])
                )
            )
        )
    ]
)]
class SetMangaPreferredSourcesResource
{
    public function __construct(
        #[Assert\NotNull]
        #[Assert\All([
            new Assert\Type('string')
        ])]
        public array $sourceIds = []
    ) {
    }
}
