<?php


namespace AutoAdmin\Bundle\Admin\Attribute;

class ClassAttributes
{
    private array $attributes;

    public function __construct(array $attributes)
    {
        $this->attributes = $attributes;
    }

    /**
     * @return PropertyAttributes[]
     */
    public function getAttributesByType(string $attributeFqcn): array
    {
        $attributes = $this->attributes;
        $attributes = array_filter(
            $attributes,
            function (PropertyAttributes $propertyAttributes) use ($attributeFqcn) {
                return $propertyAttributes->hasAttribute($attributeFqcn);
            }
        );

        return $attributes;
    }

    public function getAttributesByProperty(string $property): ?PropertyAttributes
    {
        return $this->attributes[$property] ?? null;
    }
}
