<?php

namespace App\Controller\Blog;

use App\Core\Controller\Site\PageController;
use App\Core\Site\SiteRequest;
use App\Core\Site\SiteStore;
use App\Repository\Blog\CategoryRepositoryQuery;
use Symfony\Component\HttpFoundation\Response;

class CategoryController extends PageController
{
    protected CategoryRepositoryQuery $categoryQuery;

    public function __construct(CategoryRepositoryQuery $categoryQuery, SiteRequest $siteRequest, SiteStore $siteStore)
    {
        parent::__construct($siteRequest, $siteStore);

        $this->categoryQuery = $categoryQuery;
    }

    public function categories(): Response
    {
        $entities = $this->createQuery()->find();

        return $this->defaultRender($this->siteRequest->getPage()->getTemplate(), [
            'categories' => $entities,
        ]);
    }

    public function createQuery(): CategoryRepositoryQuery
    {
        return $this->categoryQuery->create()
            ->orderBy('.title', 'ASC')
            ->andWhere('.isActive = 1')
        ;
    }
}
