Files
fotospiel-app/app/Services/AiEditing/AiStylingEntitlementService.php
Codex Agent d2808ffa4f
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
feat(addons): finalize event addon catalog and ai styling upgrade flow
2026-02-07 12:35:07 +01:00

63 lines
1.6 KiB
PHP

<?php
namespace App\Services\AiEditing;
use App\Models\Event;
use App\Services\Addons\EventFeatureEntitlementService;
class AiStylingEntitlementService
{
public function __construct(private readonly EventFeatureEntitlementService $featureEntitlements) {}
public function packageFeatureKey(): string
{
$featureKey = trim((string) config('ai-editing.entitlements.package_feature', 'ai_styling'));
return $featureKey !== '' ? $featureKey : 'ai_styling';
}
/**
* @return array<int, string>
*/
public function addonKeys(): array
{
return array_values(array_filter(array_map(
static fn (mixed $key): string => trim((string) $key),
(array) config('ai-editing.entitlements.addon_keys', ['ai_styling_unlock'])
)));
}
public function lockedMessage(): string
{
$message = trim((string) config('ai-editing.entitlements.locked_message', ''));
if ($message !== '') {
return $message;
}
return 'AI editing requires the Premium package or the AI Styling add-on.';
}
/**
* @return array{
* allowed: bool,
* granted_by: 'package'|'addon'|null,
* required_feature: string,
* addon_keys: array<int, string>
* }
*/
public function resolveForEvent(Event $event): array
{
return $this->featureEntitlements->resolveForEvent(
$event,
$this->packageFeatureKey(),
$this->addonKeys(),
);
}
public function hasAccessForEvent(Event $event): bool
{
return (bool) $this->resolveForEvent($event)['allowed'];
}
}