feat(admin): resource booking mode with a readiness guard

Task 06's engine could only be switched on through the API, and nothing
checked whether the environment was ready for it. Since the mode choice is
irreversible, picking it with no resources defined would lock a clinic into a
state where no appointment is ever computable.

Backend now refuses that: resource mode requires at least one active resource,
with a message that says what to define first. Same shape as the existing
service-mode guard, applied on both save paths.

The panel shows the same conditions as a ✓/✗ list before the choice is made,
each unmet one linking to where it gets fixed — a 422 after an irreversible
decision is the wrong place to learn about a prerequisite.

Also adds the search step (minimum 5 minutes) and extends the existing mode
cards to three rather than building a parallel component.

No strategy picker: task 06 never built the strategies, and an empty menu reads
worse than an absent one.

GET /api/v1/service-items now returns has_segments, computed with one aggregate
query for the whole list rather than one per service.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-31 19:51:29 +03:30
co-authored by Claude Opus 5
parent 1d6855a2b0
commit d56c41c87e
8 changed files with 318 additions and 16 deletions
@@ -71,6 +71,34 @@ class SegmentTemplateRepository extends ServiceEntityRepository
return $byService;
}
/**
* کدام سرویس‌ها اصلاً بخش تعریف‌شده دارند — یک کوئری، نه یکی per سرویس.
*
* @param int[] $serviceIds
* @return array<int, bool> شناسهٔ سرویس => دارد/ندارد
*/
public function hasSegmentsMap(array $serviceIds): array
{
if ($serviceIds === []) {
return [];
}
$rows = $this->createQueryBuilder('s')
->select('IDENTITY(s.service) AS service_id', 'COUNT(s.id) AS total')
->where('IDENTITY(s.service) IN (:ids)')
->setParameter('ids', $serviceIds)
->groupBy('service_id')
->getQuery()
->getArrayResult();
$map = [];
foreach ($rows as $row) {
$map[(int) $row['service_id']] = ((int) $row['total']) > 0;
}
return $map;
}
public function deleteForService(ServiceItem $service): int
{
return (int) $this->createQueryBuilder('s')