<?php

declare(strict_types=1);

namespace App\Service;

use App\Entity\Awardee;
use Doctrine\ORM\EntityManager;

class AwardeeManager
{
    /** @var EntityManager */
    private $entityManager;

    public function __construct(EntityManager $entityManager)
    {
        $this->entityManager = $entityManager;
    }

    /**
     * @param int $year
     * @return Awardee[]
     */
    public function getJudgesByYear(int $year): ?array
    {
        return $this->entityManager->getRepository(Awardee::class)->findBy([
            'year' => $year,
        ]);
    }

    /**
     * @param string $slug
     * @return Awardee|null
     */
    public function getJudgeFromSlug(string $slug): ?Awardee
    {
        /** @var Awardee $awardee */
        $awardee = $this->entityManager->getRepository(Awardee::class)->findOneBy([
           'slug' => $slug,
        ]);
        return $awardee;
    }
}
