<?php

namespace AutoAdmin\Bundle\BrickBuilder\Service;

use AutoAdmin\Bundle\BrickBuilder\Model\BrickInterface;

class BrickService
{
    public function isOrHasChildOfType(?BrickInterface $brick, string $type): bool
    {
        if (!$brick) {
            return false;
        }

        if ($brick->getType() === $type) {
            return true;
        }

        foreach ($brick->getChildren() as $child) {
            if ($this->isOrHasChildOfType($child, $type)) {
                return true;
            }
        }

        return false;
    }
}
