<?php

declare(strict_types=1);

namespace App\Repository;

use App\Entity\GameMode;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<GameMode>
 */
class GameModeRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, GameMode::class);
    }

    /** @return list<GameMode> */
    public function findAllSortedByStartScore(): array
    {
        return $this->createQueryBuilder('m')
            ->orderBy('m.startScore', 'ASC')
            ->getQuery()
            ->getResult();
    }

    public function findOneByKey(string $key): ?GameMode
    {
        return $this->findOneBy(['key' => $key]);
    }
}
