<?php

declare(strict_types=1);

namespace App\Module\Integration\Infrastructure\ApiPlatform\Resource;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Put;
use App\Module\Integration\Infrastructure\ApiPlatform\State\BookStackSettingsProcessor;
use App\Module\Integration\Infrastructure\ApiPlatform\State\BookStackSettingsProvider;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/settings/bookstack',
            normalizationContext: ['groups' => ['bookstack_settings:read']],
            provider: BookStackSettingsProvider::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
        new Put(
            uriTemplate: '/settings/bookstack',
            denormalizationContext: ['groups' => ['bookstack_settings:write']],
            normalizationContext: ['groups' => ['bookstack_settings:read']],
            provider: BookStackSettingsProvider::class,
            processor: BookStackSettingsProcessor::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
    ],
)]
final class BookStackSettings
{
    #[Groups(['bookstack_settings:read', 'bookstack_settings:write'])]
    public ?string $url = null;

    #[Groups(['bookstack_settings:write'])]
    public ?string $tokenId = null;

    #[Groups(['bookstack_settings:write'])]
    public ?string $tokenSecret = null;

    #[Groups(['bookstack_settings:read'])]
    public bool $hasToken = false;
}
