<?php

namespace App\Appointment\Plan\Repository;

use App\Appointment\Plan\Entity\SegmentRequirement;
use App\Appointment\Plan\Entity\SegmentTemplate;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    public function deleteForSegment(SegmentTemplate $segment): int
    {
        return (int) $this->createQueryBuilder('r')
            ->delete()
            ->where('r.segment = :segment')
            ->setParameter('segment', $segment)
            ->getQuery()
            ->execute();
    }
}
