Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| SeedCapacityPlansAction | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| execute | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Billing\Application\Actions; |
| 6 | |
| 7 | use ImovelZapAi\Organizations\Infrastructure\Persistence\Eloquent\SubscriptionPlanModel; |
| 8 | |
| 9 | final class SeedCapacityPlansAction |
| 10 | { |
| 11 | /** |
| 12 | * @return list<SubscriptionPlanModel> |
| 13 | */ |
| 14 | public function execute(): array |
| 15 | { |
| 16 | /** @var array<string, array<string, mixed>> $definitions */ |
| 17 | $definitions = (array) config('billing.plans', []); |
| 18 | $plans = []; |
| 19 | |
| 20 | foreach ($definitions as $code => $definition) { |
| 21 | $plans[] = SubscriptionPlanModel::query()->updateOrCreate( |
| 22 | ['code' => (string) $code], |
| 23 | [ |
| 24 | 'name' => (string) $definition['name'], |
| 25 | 'price_monthly_cents' => (int) ($definition['price_monthly_cents'] ?? 0), |
| 26 | 'price_yearly_cents' => (int) ($definition['price_yearly_cents'] ?? 0), |
| 27 | 'sort_order' => (int) ($definition['sort_order'] ?? 0), |
| 28 | 'max_users' => (int) ($definition['max_users'] ?? 0), |
| 29 | 'max_properties' => (int) ($definition['max_properties'] ?? 0), |
| 30 | 'max_whatsapp_messages_month' => (int) ($definition['max_whatsapp_messages_month'] ?? 0), |
| 31 | 'features' => $definition['features'] ?? [], |
| 32 | 'is_active' => true, |
| 33 | ], |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | // Legacy agency plan kept inactive for historical rows. |
| 38 | SubscriptionPlanModel::query() |
| 39 | ->where('code', 'agency') |
| 40 | ->update([ |
| 41 | 'is_active' => false, |
| 42 | 'name' => 'Imobiliária (legado)', |
| 43 | ]); |
| 44 | |
| 45 | return $plans; |
| 46 | } |
| 47 | } |