<?php

declare(strict_types=1);

namespace App\Framework\Validation\Rules;

use App\Framework\Validation\GroupAware;
use Attribute;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
final class ValidationGroup implements GroupAware
{
    /** @var array<string> */
    private array $groups;

    /**
     * @param string|array<string> $groups Name der Gruppe oder Gruppen
     */
    public function __construct(string|array $groups)
    {
        $this->groups = is_array($groups) ? $groups : [$groups];
    }

    /**
     * Prüft, ob das Attribut zu einer bestimmten Gruppe gehört
     */
    public function belongsToGroup(string $group): bool
    {
        return in_array($group, $this->groups, true);
    }
}
