<?php


namespace AutoAdmin\Bundle\BrickBuilder\Attributes;

use Attribute;
use BadMethodCallException;
use function get_class;

#[Attribute(Attribute::TARGET_PROPERTY)]
class BrickBuilder
{
    private ?string $type = null;
    private array $options = [];

    public function __construct(array $data = [])
    {
        foreach ($data as $key => $value) {
            $method = 'set' . str_replace('_', '', $key);
            if (!method_exists($this, $method)) {
                throw new BadMethodCallException(sprintf('Unknown property "%s" on attribute "%s".', $key, get_class($this)));
            }
            $this->$method($value);
        }
    }

    public function getType(): ?string
    {
        return $this->type;
    }

    public function setType($type): void
    {
        $this->type = $type;
    }

    public function getOptions(): array
    {
        return $this->options;
    }

    public function setOptions(array $options): void
    {
        $this->options = $options;
    }
}
