Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 98
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeedAutomationTemplatesAction
0.00% covered (danger)
0.00%
0 / 98
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 98
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Automation\Application\Actions;
6
7use ImovelZapAi\Automation\Domain\Enums\ActionKey;
8use ImovelZapAi\Automation\Domain\Enums\TriggerEventKey;
9use ImovelZapAi\Automation\Infrastructure\Persistence\Eloquent\AutomationTemplateModel;
10
11final class SeedAutomationTemplatesAction
12{
13    public function execute(): void
14    {
15        $templates = [
16            [
17                'slug' => 'nova-pessoa',
18                'name' => 'Boas-vindas — nova oportunidade',
19                'description' => 'Cria tarefa, notificação e lembrete quando uma oportunidade é criada.',
20                'category' => 'Oportunidades',
21                'definition' => [
22                    'name' => 'Boas-vindas — nova oportunidade',
23                    'trigger' => ['event_key' => TriggerEventKey::DealCreated->value],
24                    'actions' => [
25                        [
26                            'action_key' => ActionKey::CreateTask->value,
27                            'config' => [
28                                'title' => 'Contato inicial com a pessoa',
29                                'type' => 'follow_up',
30                            ],
31                            'delay_seconds' => 0,
32                            'sort_order' => 0,
33                        ],
34                        [
35                            'action_key' => ActionKey::CreateNotification->value,
36                            'config' => [
37                                'title' => 'Nova oportunidade',
38                                'body' => 'Uma nova oportunidade foi registrada.',
39                            ],
40                            'delay_seconds' => 60,
41                            'sort_order' => 1,
42                        ],
43                        [
44                            'action_key' => ActionKey::CreateReminder->value,
45                            'config' => ['title' => 'Retornar contato em 24h'],
46                            'delay_seconds' => 3600,
47                            'sort_order' => 2,
48                        ],
49                    ],
50                    'activate' => false,
51                ],
52            ],
53            [
54                'slug' => 'contrato-assinado',
55                'name' => 'Contrato assinado',
56                'description' => 'Notifica e cria tarefa quando a assinatura é concluída.',
57                'category' => 'Assinaturas',
58                'definition' => [
59                    'name' => 'Contrato assinado',
60                    'trigger' => ['event_key' => TriggerEventKey::SignatureCompleted->value],
61                    'actions' => [
62                        [
63                            'action_key' => ActionKey::CreateNotification->value,
64                            'config' => [
65                                'title' => 'Assinatura concluída',
66                                'body' => 'O contrato foi assinado por todas as partes.',
67                            ],
68                            'sort_order' => 0,
69                        ],
70                        [
71                            'action_key' => ActionKey::CreateTask->value,
72                            'config' => [
73                                'title' => 'Iniciar pós-assinatura',
74                                'type' => 'post_sale',
75                            ],
76                            'sort_order' => 1,
77                        ],
78                    ],
79                ],
80            ],
81            [
82                'slug' => 'documento-recusado',
83                'name' => 'Documento recusado',
84                'description' => 'Notifica a equipe quando um documento é recusado.',
85                'category' => 'Documentos',
86                'definition' => [
87                    'name' => 'Documento recusado',
88                    'trigger' => ['event_key' => TriggerEventKey::DocumentRejected->value],
89                    'actions' => [
90                        [
91                            'action_key' => ActionKey::CreateNotification->value,
92                            'config' => [
93                                'title' => 'Documento recusado',
94                                'body' => 'Revise o documento e solicite correção à pessoa.',
95                            ],
96                            'sort_order' => 0,
97                        ],
98                    ],
99                ],
100            ],
101        ];
102
103        foreach ($templates as $template) {
104            AutomationTemplateModel::query()->updateOrCreate(
105                ['slug' => $template['slug']],
106                [
107                    'name' => $template['name'],
108                    'description' => $template['description'],
109                    'category' => $template['category'],
110                    'definition' => $template['definition'],
111                    'is_active' => true,
112                ],
113            );
114        }
115    }
116}