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

#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/settings/zimbra',
            normalizationContext: ['groups' => ['zimbra_settings:read']],
            provider: ZimbraSettingsProvider::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
        new Put(
            uriTemplate: '/settings/zimbra',
            denormalizationContext: ['groups' => ['zimbra_settings:write']],
            normalizationContext: ['groups' => ['zimbra_settings:read']],
            provider: ZimbraSettingsProvider::class,
            processor: ZimbraSettingsProcessor::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
    ],
)]
final class ZimbraSettings
{
    #[Groups(['zimbra_settings:read', 'zimbra_settings:write'])]
    public ?string $serverUrl = null;

    #[Groups(['zimbra_settings:read', 'zimbra_settings:write'])]
    public ?string $username = null;

    #[Groups(['zimbra_settings:read', 'zimbra_settings:write'])]
    public ?string $calendarPath = null;

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

    #[Groups(['zimbra_settings:read', 'zimbra_settings:write'])]
    public bool $enabled = false;

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