Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| AnalyticsEventKey | |
0.00% |
0 / 57 |
|
0.00% |
0 / 6 |
2550 | |
0.00% |
0 / 1 |
| eventClass | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
240 | |||
| label | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
240 | |||
| metricKeys | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
240 | |||
| tryFromEvent | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| eventClasses | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| subscribedEventClasses | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Analytics\Domain\Enums; |
| 6 | |
| 7 | use ImovelZapAi\Automation\Domain\Events\WorkflowExecuted; |
| 8 | use ImovelZapAi\ClientPortal\Domain\Events\PortalDocumentUploaded; |
| 9 | use ImovelZapAi\Documents\Domain\Events\DocumentCreated; |
| 10 | use ImovelZapAi\Documents\Domain\Events\DocumentRejected; |
| 11 | use ImovelZapAi\Financial\Domain\Events\CommissionCalculated; |
| 12 | use ImovelZapAi\Financial\Domain\Events\PaymentReceived; |
| 13 | use ImovelZapAi\Sales\Domain\Events\DealCreated; |
| 14 | use ImovelZapAi\Sales\Domain\Events\DealStageChanged; |
| 15 | use ImovelZapAi\Sales\Domain\Events\DealWon; |
| 16 | use ImovelZapAi\Signatures\Domain\Events\SignatureCompleted; |
| 17 | use ImovelZapAi\Signatures\Domain\Events\SignatureRequested; |
| 18 | use ImovelZapAi\Visits\Domain\Events\VisitCompleted; |
| 19 | use ImovelZapAi\Visits\Domain\Events\VisitConfirmed; |
| 20 | use ImovelZapAi\Visits\Domain\Events\VisitCreated; |
| 21 | |
| 22 | enum AnalyticsEventKey: string |
| 23 | { |
| 24 | case DealCreated = 'deal.created'; |
| 25 | case DealStageChanged = 'deal.stage_changed'; |
| 26 | case DealWon = 'deal.won'; |
| 27 | case VisitCreated = 'visit.created'; |
| 28 | case VisitConfirmed = 'visit.confirmed'; |
| 29 | case VisitCompleted = 'visit.completed'; |
| 30 | case SignatureRequested = 'signature.requested'; |
| 31 | case SignatureCompleted = 'signature.completed'; |
| 32 | case PaymentReceived = 'payment.received'; |
| 33 | case CommissionCalculated = 'commission.calculated'; |
| 34 | case DocumentCreated = 'document.created'; |
| 35 | case DocumentRejected = 'document.rejected'; |
| 36 | case PortalDocumentUploaded = 'portal.document_uploaded'; |
| 37 | case WorkflowExecuted = 'workflow.executed'; |
| 38 | |
| 39 | public function eventClass(): string |
| 40 | { |
| 41 | return match ($this) { |
| 42 | self::DealCreated => DealCreated::class, |
| 43 | self::DealStageChanged => DealStageChanged::class, |
| 44 | self::DealWon => DealWon::class, |
| 45 | self::VisitCreated => VisitCreated::class, |
| 46 | self::VisitConfirmed => VisitConfirmed::class, |
| 47 | self::VisitCompleted => VisitCompleted::class, |
| 48 | self::SignatureRequested => SignatureRequested::class, |
| 49 | self::SignatureCompleted => SignatureCompleted::class, |
| 50 | self::PaymentReceived => PaymentReceived::class, |
| 51 | self::CommissionCalculated => CommissionCalculated::class, |
| 52 | self::DocumentCreated => DocumentCreated::class, |
| 53 | self::DocumentRejected => DocumentRejected::class, |
| 54 | self::PortalDocumentUploaded => PortalDocumentUploaded::class, |
| 55 | self::WorkflowExecuted => WorkflowExecuted::class, |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | public function label(): string |
| 60 | { |
| 61 | return match ($this) { |
| 62 | self::DealCreated => 'Oportunidade criada', |
| 63 | self::DealStageChanged => 'Etapa alterada', |
| 64 | self::DealWon => 'Oportunidade ganha', |
| 65 | self::VisitCreated => 'Visita agendada', |
| 66 | self::VisitConfirmed => 'Visita confirmada', |
| 67 | self::VisitCompleted => 'Visita concluída', |
| 68 | self::SignatureRequested => 'Assinatura solicitada', |
| 69 | self::SignatureCompleted => 'Assinatura concluída', |
| 70 | self::PaymentReceived => 'Pagamento recebido', |
| 71 | self::CommissionCalculated => 'Comissão calculada', |
| 72 | self::DocumentCreated => 'Documento criado', |
| 73 | self::DocumentRejected => 'Documento recusado', |
| 74 | self::PortalDocumentUploaded => 'Documento no portal', |
| 75 | self::WorkflowExecuted => 'Automação executada', |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | /** @return list<MetricKey> */ |
| 80 | public function metricKeys(): array |
| 81 | { |
| 82 | return match ($this) { |
| 83 | self::DealCreated => [MetricKey::PeopleOpportunitiesCreated], |
| 84 | self::DealWon => [MetricKey::DealsWon, MetricKey::VolumeNegotiated], |
| 85 | self::VisitCreated => [MetricKey::VisitsCreated], |
| 86 | self::VisitConfirmed => [MetricKey::VisitsConfirmed], |
| 87 | self::VisitCompleted => [MetricKey::VisitsCompleted], |
| 88 | self::SignatureRequested => [MetricKey::SignaturesRequested], |
| 89 | self::SignatureCompleted => [MetricKey::SignaturesCompleted], |
| 90 | self::PaymentReceived => [MetricKey::PaymentsReceivedCount, MetricKey::PaymentsReceivedAmount], |
| 91 | self::CommissionCalculated => [MetricKey::CommissionsCalculated], |
| 92 | self::DocumentCreated => [MetricKey::DocumentsCreated], |
| 93 | self::DocumentRejected => [MetricKey::DocumentsRejected], |
| 94 | self::PortalDocumentUploaded => [MetricKey::PortalDocumentsUploaded], |
| 95 | self::WorkflowExecuted => [MetricKey::WorkflowsExecuted], |
| 96 | default => [], |
| 97 | }; |
| 98 | } |
| 99 | |
| 100 | public static function tryFromEvent(object $event): ?self |
| 101 | { |
| 102 | foreach (self::cases() as $case) { |
| 103 | if ($event instanceof ($case->eventClass())) { |
| 104 | return $case; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return null; |
| 109 | } |
| 110 | |
| 111 | /** @return list<string> */ |
| 112 | public static function eventClasses(): array |
| 113 | { |
| 114 | return array_map(static fn (self $case) => $case->eventClass(), self::cases()); |
| 115 | } |
| 116 | |
| 117 | /** @return list<string> */ |
| 118 | public static function subscribedEventClasses(): array |
| 119 | { |
| 120 | return array_values(array_filter( |
| 121 | self::eventClasses(), |
| 122 | static fn (string $class) => $class !== WorkflowExecuted::class, |
| 123 | )); |
| 124 | } |
| 125 | } |