<?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\GiteaSettingsProcessor;
use App\Module\Integration\Infrastructure\ApiPlatform\State\GiteaSettingsProvider;
use Symfony\Component\Serializer\Attribute\Groups;

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

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

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