Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.3 KB
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Services\Domain\LifecycleEmail\Nudges;

use HiEvents\DomainObjects\Enums\LifecycleNudgeType;

class LifecycleNudgeRegistry
{
    public function __construct(
        private readonly NoEventCreatedNudge $noEventCreated,
        private readonly StripeOnboardingIncompleteNudge $stripeOnboardingIncomplete,
        private readonly EventDraftStaleNudge $eventDraftStale,
        private readonly LiveEventNoSalesNudge $liveEventNoSales,
        private readonly LapsedPayerNudge $lapsedPayer,
    ) {}

    public function for(LifecycleNudgeType $type): LifecycleNudgeInterface
    {
        return match ($type) {
            LifecycleNudgeType::NO_EVENT_CREATED => $this->noEventCreated,
            LifecycleNudgeType::STRIPE_ONBOARDING_INCOMPLETE => $this->stripeOnboardingIncomplete,
            LifecycleNudgeType::EVENT_DRAFT_STALE => $this->eventDraftStale,
            LifecycleNudgeType::LIVE_EVENT_NO_SALES => $this->liveEventNoSales,
            LifecycleNudgeType::LAPSED_PAYER => $this->lapsedPayer,
        };
    }

    /**
     * @return array<int, LifecycleNudgeInterface>
     */
    public function all(): array
    {
        return array_map(fn (LifecycleNudgeType $type) => $this->for($type), LifecycleNudgeType::cases());
    }
}