<?php

declare(strict_types=1);

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

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Patch;
use App\Module\Mail\Infrastructure\ApiPlatform\State\MailSettingsProcessor;
use App\Module\Mail\Infrastructure\ApiPlatform\State\MailSettingsProvider;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/mail/configuration',
            normalizationContext: ['groups' => ['mail_settings:read']],
            provider: MailSettingsProvider::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
        new Patch(
            uriTemplate: '/mail/configuration',
            denormalizationContext: ['groups' => ['mail_settings:write']],
            normalizationContext: ['groups' => ['mail_settings:read']],
            provider: MailSettingsProvider::class,
            processor: MailSettingsProcessor::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
    ],
)]
final class MailSettings
{
    #[Groups(['mail_settings:read', 'mail_settings:write'])]
    public ?string $protocol = null;

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

    #[Groups(['mail_settings:read', 'mail_settings:write'])]
    public ?int $imapPort = null;

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

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

    #[Groups(['mail_settings:read', 'mail_settings:write'])]
    public ?int $smtpPort = null;

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

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

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

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

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

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