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

#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/settings/share',
            normalizationContext: ['groups' => ['share_settings:read']],
            provider: ShareSettingsProvider::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
        new Put(
            uriTemplate: '/settings/share',
            denormalizationContext: ['groups' => ['share_settings:write']],
            normalizationContext: ['groups' => ['share_settings:read']],
            provider: ShareSettingsProvider::class,
            processor: ShareSettingsProcessor::class,
            security: "is_granted('ROLE_ADMIN')",
        ),
    ],
)]
final class ShareSettings
{
    #[Groups(['share_settings:read', 'share_settings:write'])]
    public ?string $host = null;

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

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

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

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

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

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

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