<?php

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

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

#[ApiResource(
    shortName: 'MangaMonitoring',
    operations: [
        new Post(
            uriTemplate: '/manga/{mangaId}/monitoring/toggle',
            processor: ToggleMonitoringProcessor::class,
            read: false,
            status: 204,
            description: 'Active ou désactive le monitoring automatique d\'un manga',
            openapiContext: [
                'summary' => 'Activer/Désactiver le monitoring d\'un manga',
                'description' => 'Active ou désactive le monitoring automatique pour recevoir les nouveaux chapitres',
                'parameters' => [
                    [
                        'name' => 'mangaId',
                        'in' => 'path',
                        'required' => true,
                        'schema' => ['type' => 'string'],
                        'description' => 'L\'identifiant unique du manga'
                    ]
                ],
                'requestBody' => [
                    'description' => 'État du monitoring à appliquer',
                    'required' => true,
                    'content' => [
                        'application/json' => [
                            'schema' => [
                                'type' => 'object',
                                'properties' => [
                                    'enabled' => [
                                        'type' => 'boolean',
                                        'description' => 'True pour activer le monitoring, false pour le désactiver',
                                        'example' => true
                                    ]
                                ],
                                'required' => ['enabled']
                            ]
                        ]
                    ]
                ],
                'responses' => [
                    '204' => [
                        'description' => 'Monitoring modifié avec succès'
                    ],
                    '404' => [
                        'description' => 'Manga non trouvé'
                    ],
                    '422' => [
                        'description' => 'Données de validation invalides'
                    ]
                ]
            ]
        )
    ]
)]
class ToggleMonitoringResource
{
    #[Assert\NotNull(message: 'Le champ enabled est obligatoire')]
    #[Assert\Type(type: 'boolean', message: 'Cette valeur doit être de type bool.')]
    public mixed $enabled = null;
}
