<?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
     *
     * @var int
     */
    #[ApiProperty(identifier: true)]
    protected int $id = 0;

    /**
     * The subdomain
     * @var string
     */
    private string $subdomain;

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

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

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

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

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

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

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