*/ public function categories(): array { return (array) config('care_workflows.categories', []); } /** @return array */ public function category(?string $key): ?array { if ($key === null || $key === '') { return null; } $category = config("care_workflows.categories.{$key}"); return is_array($category) ? $category : null; } /** @return array key => label */ public function categoryOptions(): array { return array_map( fn (array $category) => (string) ($category['label'] ?? ''), $this->categories(), ); } /** @return array */ public function templates(): array { return (array) config('care_workflows.templates', []); } /** @return array|null */ public function template(?string $key): ?array { if ($key === null || $key === '') { return null; } $template = config("care_workflows.templates.{$key}"); return is_array($template) ? $template : null; } public function hasTemplate(?string $key): bool { return $this->template($key) !== null; } /** @return array key => label */ public function templateOptions(): array { return array_map( fn (array $template) => (string) ($template['label'] ?? ''), $this->templates(), ); } public function defaultTemplateKey(): string { return (string) config('care_workflows.default_template', 'legacy_clinic'); } /** Preferred template for a facility category, falling back to the global default. */ public function defaultTemplateForCategory(?string $categoryKey): string { $category = $this->category($categoryKey); $preferred = $category['default_template'] ?? null; if (is_string($preferred) && $this->hasTemplate($preferred)) { return $preferred; } return $this->defaultTemplateKey(); } /** @return list */ public function modulesForCategory(?string $categoryKey): array { $category = $this->category($categoryKey); return array_values((array) ($category['modules'] ?? [])); } }