public function getRuleCount(int $ruleStatus, ?Layout $layout = null): int
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('count(*) AS count')
            ->from('ngbm_rule');

        if ($layout instanceof Layout) {
            $query->andWhere(
                $query->expr()->eq('layout_id', ':layout_id')
            )
            ->setParameter('layout_id', $layout->id, Type::INTEGER);
        }

        $this->applyStatusCondition($query, $ruleStatus);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return (int) ($data[0]['count'] ?? 0);
    }