<?php

namespace App\Repository;

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

final class ChildRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Child::class);
    }

    /** @return list<Child> */
    public function findActiveForFamily(Family $family): array
    {
        return $this->createQueryBuilder('child')
            ->andWhere('child.family = :family')
            ->andWhere('child.active = true')
            ->setParameter('family', $family)
            ->orderBy('child.displayOrder', 'ASC')
            ->addOrderBy('child.firstName', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
