<?php

declare(strict_types=1);

namespace App\Handler;

use App\Service\JudgeManager;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Expressive\Template\TemplateRendererInterface;

class JudgesHandler implements RequestHandlerInterface
{
    /** @var TemplateRendererInterface */
    private $template;

    /** @var JudgeManager */
    private $judgeManager;

    public function __construct(
        TemplateRendererInterface $template,
        JudgeManager $judgeManager
    ) {
        $this->template = $template;
        $this->judgeManager = $judgeManager;
    }

    public function handle(ServerRequestInterface $request) : ResponseInterface
    {
        $data['judges'] = $this->judgeManager->getJudges();
        return new HtmlResponse($this->template->render("app::judges", $data));
    }
}
