<?php

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

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\Response;
use App\Domain\Scraping\Infrastructure\ApiPlatform\Dto\MangaPreferredSourcesDetail;
use App\Domain\Scraping\Infrastructure\ApiPlatform\State\Provider\GetMangaPreferredSourcesStateProvider;

#[ApiResource(
    shortName: 'Scraping',
    operations: [
        new Get(
            uriTemplate: '/mangas/{id}/preferred-sources',
            provider: GetMangaPreferredSourcesStateProvider::class,
            output: MangaPreferredSourcesDetail::class,
            description: 'Récupérer les sources préférées d\'un manga ou toutes les sources si aucune préférence',
            openapi: new OpenApiOperation(
                summary: 'Récupérer les sources préférées d\'un manga',
                description: 'Retourne les sources préférées configurées pour un manga, ou toutes les sources disponibles si aucune préférence définie',
                responses: [
                    '200' => new Response(
                        description: 'Sources récupérées avec succès',
                        content: new \ArrayObject([
                            'application/json' => [
                                'schema' => [
                                    'type' => 'object',
                                    'properties' => [
                                        'mangaId' => ['type' => 'string'],
                                        'hasPreferredSources' => ['type' => 'boolean'],
                                        'sources' => [
                                            'type' => 'array',
                                            'items' => [
                                                'type' => 'object',
                                                'properties' => [
                                                    'id' => ['type' => 'string'],
                                                    'name' => ['type' => 'string'],
                                                    'baseUrl' => ['type' => 'string'],
                                                    'description' => ['type' => 'string'],
                                                    'isActive' => ['type' => 'boolean']
                                                ]
                                            ]
                                        ]
                                    ]
                                ],
                                'example' => [
                                    'mangaId' => '1',
                                    'hasPreferredSources' => true,
                                    'sources' => [
                                        [
                                            'id' => '1',
                                            'name' => 'MangaDex',
                                            'baseUrl' => 'https://mangadex.org',
                                            'description' => 'Source principale',
                                            'isActive' => true
                                        ],
                                        [
                                            'id' => '2',
                                            'name' => 'MangaKakalot',
                                            'baseUrl' => 'https://mangakakalot.com',
                                            'description' => 'Source secondaire',
                                            'isActive' => true
                                        ]
                                    ]
                                ]
                            ]
                        ])
                    )
                ]
            )
        )
    ]
)]
class GetMangaPreferredSourcesResource
{
    public function __construct(
        public string $id
    ) {
    }
}
