, collect_name: bool, collect_phone: bool, reset_seconds: int, welcome_message: ?string} */ public function settings(Device $device): array { $config = $device->config ?? []; return [ 'service_queue_ids' => array_values(array_filter(array_map( 'intval', $config['service_queue_ids'] ?? [], ))), 'collect_name' => (bool) ($config['collect_name'] ?? false), 'collect_phone' => (bool) ($config['collect_phone'] ?? false), 'reset_seconds' => max(5, (int) ($config['reset_seconds'] ?? 15)), 'welcome_message' => filled($config['welcome_message'] ?? null) ? (string) $config['welcome_message'] : null, ]; } /** * Queue IDs configured on the device (empty = all branch queues). * * @return list */ public function assignedQueueIds(Device $device): array { return $this->settings($device)['service_queue_ids']; } /** * @return Collection */ public function queuesFor(Device $device): Collection { $ids = $this->assignedQueueIds($device); $query = ServiceQueue::query() ->where('organization_id', $device->organization_id) ->where('is_active', true) ->where('is_paused', false) ->when($device->branch_id, fn ($q) => $q->where('branch_id', $device->branch_id)) ->when($ids !== [], fn ($q) => $q->whereIn('id', $ids)) ->orderBy('name'); return $query->get(); } public function queueAllowedForIssue(Device $device, int $queueId): bool { $ids = $this->assignedQueueIds($device); $query = ServiceQueue::query() ->where('organization_id', $device->organization_id) ->where('id', $queueId) ->when($device->branch_id, fn ($q) => $q->where('branch_id', $device->branch_id)) ->when($ids !== [], fn ($q) => $q->whereIn('id', $ids)); return $query->exists(); } }