<?php

declare(strict_types=1);

namespace App\Repository;

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

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

    /** @return list<GamePlayer> */
    public function findByGameOrdered(Game $game): array
    {
        return $this->createQueryBuilder('p')
            ->where('p.game = :game')
            ->setParameter('game', $game)
            ->orderBy('p.position', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
