<?php

declare(strict_types=1);

namespace App\SuperAdmin\Infrastructure\Api\Resource;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use App\SuperAdmin\Infrastructure\Api\Processor\CreateEstablishmentProcessor;
use App\SuperAdmin\Infrastructure\Api\Provider\EstablishmentCollectionProvider;
use App\SuperAdmin\Infrastructure\Api\Provider\EstablishmentItemProvider;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
    shortName: 'Establishment',
    operations: [
        new GetCollection(
            uriTemplate: '/super-admin/establishments',
            provider: EstablishmentCollectionProvider::class,
            security: "is_granted('ROLE_SUPER_ADMIN')",
            name: 'super_admin_establishments_list',
        ),
        new Get(
            uriTemplate: '/super-admin/establishments/{id}',
            provider: EstablishmentItemProvider::class,
            security: "is_granted('ROLE_SUPER_ADMIN')",
            name: 'super_admin_establishments_detail',
        ),
        new Post(
            uriTemplate: '/super-admin/establishments',
            processor: CreateEstablishmentProcessor::class,
            security: "is_granted('ROLE_SUPER_ADMIN')",
            validationContext: ['groups' => ['Default', 'create']],
            name: 'super_admin_establishments_create',
        ),
    ],
)]
final class EstablishmentResource
{
    public ?string $id = null;
    public ?string $tenantId = null;

    #[Assert\NotBlank(groups: ['create'])]
    #[Assert\Length(max: 255, groups: ['create'])]
    public string $name = '';

    #[Assert\NotBlank(groups: ['create'])]
    #[Assert\Length(max: 100, groups: ['create'])]
    #[Assert\Regex(pattern: '/^[a-z0-9-]+$/', message: 'Le sous-domaine ne peut contenir que des lettres minuscules, chiffres et tirets.', groups: ['create'])]
    public string $subdomain = '';

    #[Assert\NotBlank(groups: ['create'])]
    #[Assert\Email(groups: ['create'])]
    public string $adminEmail = '';

    public ?string $databaseName = null;
    public ?string $status = null;
    public ?string $createdAt = null;
    public ?string $lastActivityAt = null;
}
