<?php

namespace App\Appointment\Booking\Repository;

use App\Appointment\Booking\Entity\AppointmentSegment;
use App\Appointment\Entity\Appointment;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    /** @return AppointmentSegment[] */
    public function findForAppointment(Appointment $appointment): array
    {
        return $this->createQueryBuilder('s')
            ->where('s.appointment = :appointment')
            ->setParameter('appointment', $appointment)
            ->orderBy('s.sequence', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
