<?php

namespace App\Dto\Output;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;
use App\Entity\User;
use App\Entity\UserGroup;
use Symfony\Component\Serializer\Annotation\Groups;

#[Get(shortName: 'UserGroup')]
final class UserGroupOutput extends AbstractOutput
{
    #[Groups(['user-group:read', 'user:read'])]
    #[ApiProperty(
        description: 'El nombre del grupo de usuarios',
        example: 'Administradores'
    )]
    public string $name;

    #[Groups(['user-group:read'])]
    #[ApiProperty(
        description: 'Los permisos asignados al grupo',
        example: ['clients.read', 'clients.write', 'images.read']
    )]
    public array $permissions;

    #[Groups(['user-group:read'])]
    #[ApiProperty(
        description: 'Indica si el grupo está habilitado',
        example: true
    )]
    public bool $enabled;

    #[Groups(['user-group:read'])]
    #[ApiProperty(
        description: 'Fecha de creación del grupo de usuarios',
        example: '2024-01-15T10:30:00+00:00'
    )]
    public \DateTime $createdAt;

    #[Groups(['user-group:read'])]
    #[ApiProperty(
        description: 'Usuario que creó este registro',
        example: 'admin'
    )]
    public ?string $createdBy = null;

    public function __construct(UserGroup $userGroup)
    {
        parent::__construct($userGroup);

        $this->name = $userGroup->getName();
        $this->permissions = $userGroup->getPermissions();
        $this->enabled = $userGroup->isEnabled();
        $this->createdAt = $userGroup->getCreatedAt();
        $this->createdBy = $userGroup->getCreatedBy();
    }
}