<?php


namespace App\Model\Facades\Readers;


use App\Model\Entities\Interfaces\INavItem;
use App\Model\Services\NavigationService;

class NavigationReader extends BaseReader
{
    /** @var NavigationService */
    protected $navigationService;
    /** @var SiteReader */
    protected $siteReader;

    public function __construct(NavigationService $navigationService, SiteReader $siteReader)
    {
        $this->navigationService = $navigationService;
        $this->siteReader = $siteReader;
    }

    /**
     * @param $site
     * @return INavItem[]
     */
    public function getSiteNavigation($site)
    {
        $siteEntity = $this->siteReader->validateSite($site);
        $items = $this->navigationService->getNavigation($siteEntity);

        if ($items === null) {
            return [];
        }
        return $items;
    }

    public function findHomepage($site) : INavItem
    {
        $siteEntity = $this->siteReader->validateSite($site);
        $homepage = $this->navigationService->findHomepage($siteEntity);
        $this->validateEntity($homepage);

        return $homepage;
    }

}