Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SeedSubscriptionPlansAction | |
0.00% |
0 / 47 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 47 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Organizations\Application\Actions; |
| 6 | |
| 7 | use ImovelZapAi\Organizations\Infrastructure\Persistence\Eloquent\SubscriptionPlanModel; |
| 8 | |
| 9 | final class SeedSubscriptionPlansAction |
| 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 | |
| 19 | if ($definitions === []) { |
| 20 | $definitions = [ |
| 21 | 'solo' => [ |
| 22 | 'name' => 'Solo', |
| 23 | 'sort_order' => 10, |
| 24 | 'max_users' => 1, |
| 25 | 'max_properties' => 200, |
| 26 | 'max_whatsapp_messages_month' => 2000, |
| 27 | 'price_monthly_cents' => 9700, |
| 28 | 'price_yearly_cents' => 97000, |
| 29 | 'features' => ['whatsapp', 'portal', 'ai_basic'], |
| 30 | ], |
| 31 | 'start' => [ |
| 32 | 'name' => 'Start', |
| 33 | 'sort_order' => 20, |
| 34 | 'max_users' => 5, |
| 35 | 'max_properties' => 500, |
| 36 | 'max_whatsapp_messages_month' => 10000, |
| 37 | 'price_monthly_cents' => 19700, |
| 38 | 'price_yearly_cents' => 197000, |
| 39 | 'features' => ['whatsapp', 'portal', 'ai_basic', 'manager_dashboard'], |
| 40 | ], |
| 41 | ]; |
| 42 | } |
| 43 | |
| 44 | $plans = []; |
| 45 | |
| 46 | foreach ($definitions as $code => $definition) { |
| 47 | $plans[] = SubscriptionPlanModel::query()->updateOrCreate( |
| 48 | ['code' => (string) $code], |
| 49 | [ |
| 50 | 'name' => (string) $definition['name'], |
| 51 | 'price_monthly_cents' => (int) ($definition['price_monthly_cents'] ?? 0), |
| 52 | 'price_yearly_cents' => (int) ($definition['price_yearly_cents'] ?? 0), |
| 53 | 'sort_order' => (int) ($definition['sort_order'] ?? 0), |
| 54 | 'max_users' => (int) ($definition['max_users'] ?? 1), |
| 55 | 'max_properties' => (int) ($definition['max_properties'] ?? 50), |
| 56 | 'max_whatsapp_messages_month' => (int) ($definition['max_whatsapp_messages_month'] ?? 2000), |
| 57 | 'features' => $definition['features'] ?? [], |
| 58 | 'is_active' => true, |
| 59 | ], |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | SubscriptionPlanModel::query() |
| 64 | ->where('code', 'agency') |
| 65 | ->update([ |
| 66 | 'is_active' => false, |
| 67 | 'name' => 'Imobiliária (legado)', |
| 68 | ]); |
| 69 | |
| 70 | return $plans; |
| 71 | } |
| 72 | } |