<?php

declare(strict_types=1);

namespace App\ApiResources\Organization\Subdomain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\State\Provider\Organization\Subdomain\SubdomainAvailabilityProvider;

#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/subdomains/is_available',
            security: 'is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION")',
            provider: SubdomainAvailabilityProvider::class
        ),
    ]
)]
class SubdomainAvailability
{
    /**
     * Id 'bidon' ajouté par défaut pour permettre la construction
     * de l'IRI par api platform.
     */
    #[ApiProperty(identifier: true)]
    protected int $id = 0;

    /**
     * The subdomain.
     */
    private string $subdomain;

    /**
     * Is the subdomain available (not registered nor reserved).
     */
    private bool $available;

    public function getId(): int
    {
        return $this->id;
    }

    public function setId(int $id): void
    {
        $this->id = $id;
    }

    public function getSubdomain(): string
    {
        return $this->subdomain;
    }

    public function setSubdomain(string $subdomain): void
    {
        $this->subdomain = $subdomain;
    }

    public function isAvailable(): bool
    {
        return $this->available;
    }

    public function setAvailable(bool $available): void
    {
        $this->available = $available;
    }
}
