<?php

declare(strict_types=1);

namespace KupShop\CatalogBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;

/**
 * Helpers around category saved in ArrayCollection ({@see SectionView}, {@see \KupShop\CatalogBundle\Util\SectionViewUtil}).
 */
class Category extends ArrayCollection
{
    public function getId(): ?int
    {
        if (!is_numeric($id = $this->get('id'))) {
            return null;
        }

        return (int) $id;
    }

    public function shouldFetchProductsFromSubsections(): bool
    {
        return $this->get('behaviour') == 2;
    }
}
