Verbs

Plan Report Generated

1<?php ...
2 
3namespace Thunk\Verbs\Examples\Subscriptions\Events;
4 
5use Thunk\Verbs\Attributes\Autodiscovery\StateId;
6use Thunk\Verbs\Attributes\Hooks\Once;
7use Thunk\Verbs\Event;
8use Thunk\Verbs\Examples\Subscriptions\Models\Report;
9use Thunk\Verbs\Examples\Subscriptions\States\PlanReportState;
10 
11class PlanReportGenerated extends Event
12{
13 #[StateId(PlanReportState::class)]
14 public int $plan_id;
15 
16 #[Once]
17 public function handle()
18 {
19 $state = $this->state(PlanReportState::class);
20 
21 Report::create([
22 'plan_id' => $this->plan_id,
23 'subscribes_since_last_report' => $state->subscribes_since_last_report,
24 'unsubscribes_since_last_report' => $state->unsubscribes_since_last_report,
25 'total_subscriptions' => $state->total_subscriptions,
26 'summary' => $state->summary(),
27 ]);
28 
29 ResetPlanReportState::fire(plan_id: $this->plan_id);
30 }
31}