-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseline.prisma
More file actions
1588 lines (1293 loc) · 42.1 KB
/
Copy pathbaseline.prisma
File metadata and controls
1588 lines (1293 loc) · 42.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This is your Prisma schema file
generator client {
provider = "prisma-client-js"
// native=local dev; linux-musl-*=Alpine Docker (Cloud Run). Alpine 3.17+ needs openssl-3.
binaryTargets = ["native", "linux-musl-openssl-3.0.x", "linux-musl-arm64-openssl-3.0.x"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Audit {
id String @id @default(uuid())
businessName String
businessCity String?
businessUrl String?
businessIndustry String?
verticalPlaybookId String? // e.g., 'dentist', 'law-firm' — from playbook detection
status AuditStatus @default(QUEUED)
modulesCompleted String[] @default([])
modulesFailed Json @default("[]")
overallScore Int?
apiCostCents Int @default(0)
startedAt DateTime @default(now())
completedAt DateTime?
createdAt DateTime @default(now())
batchId String?
// Multi-Tenancy
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id])
findings Finding[]
proposals Proposal[]
evidence EvidenceSnapshot[]
FindingStatus FindingStatus[]
ClientMessage ClientMessage[]
ReviewSnapshot ReviewSnapshot[]
@@index([status])
@@index([createdAt])
@@index([tenantId])
@@index([batchId])
}
model Finding {
id String @id @default(uuid())
auditId String
module String
category String
type FindingType
title String
description String?
evidence Json @default("[]")
metrics Json @default("{}")
impactScore Int
confidenceScore Int
effortEstimate EffortLevel?
recommendedFix Json @default("[]")
manuallyEdited Boolean @default(false)
excluded Boolean @default(false)
confidenceLevel String? // 'HIGH', 'MEDIUM', 'LOW' — set by Confidence Scorer
createdAt DateTime @default(now())
// Multi-Tenancy (Denormalized)
tenantId String? // Optional for migration, enforce in app logic
audit Audit @relation(fields: [auditId], references: [id], onDelete: Cascade)
FindingStatus FindingStatus[]
@@index([auditId])
@@index([type])
@@index([tenantId])
}
model Proposal {
id String @id @default(uuid())
auditId String
version Int @default(1)
status ProposalStatus @default(DRAFT)
prospectEmail String? // Added for follow-ups
executiveSummary String?
painClusters Json @default("[]")
tierEssentials Json @default("{}")
tierGrowth Json @default("{}")
tierPremium Json @default("{}")
pricing Json @default("{}")
assumptions String[] @default([])
disclaimers String[] @default([])
nextSteps String[] @default([])
comparisonReport Json? // Competitor comparison (ranking, winning/losing, quick wins)
pdfUrl String?
pdfGeneratedAt DateTime?
webLinkToken String @unique @default(uuid())
sentAt DateTime?
viewedAt DateTime?
createdAt DateTime @default(now())
// Multi-Tenancy
tenantId String?
// Template Link
templateId String?
template ProposalTemplate? @relation(fields: [templateId], references: [id])
// QA Fields
qaScore Int? @default(0)
qaResults Json @default("{}")
clientScore Int? @default(0)
clientScoreResults Json @default("{}")
humanCloseabilityScore Float?
// Win/Loss Tracking (Feature #5)
outcome ProposalOutcome?
closedAt DateTime?
dealValue Decimal? @db.Decimal(10, 2)
lostReason String?
notes String?
replyReceivedAt DateTime?
meetingBookedAt DateTime?
tierChosen String?
// Viral Sharing
shareCount Int @default(0)
audit Audit @relation(fields: [auditId], references: [id], onDelete: Cascade)
followUps ProposalFollowUp[]
outreach ProposalOutreach[]
acceptance ProposalAcceptance? // One acceptance per proposal
views ProposalView[]
contactRequests ContactRequest[]
project Project?
// Sprint 9: Conversational Closing
conversationState ConversationState?
objectionLogs ObjectionLog[]
emailSequence EmailSequence?
@@index([auditId])
@@index([webLinkToken])
@@index([status])
@@index([tenantId])
@@index([clientScore])
@@index([replyReceivedAt])
@@index([meetingBookedAt])
}
model ProposalAcceptance {
id String @id @default(uuid())
proposalId String @unique
tier String // essentials, growth, premium
contactName String
contactEmail String
contactPhone String?
message String?
ipAddress String?
acceptedAt DateTime @default(now())
proposal Proposal @relation(fields: [proposalId], references: [id], onDelete: Cascade)
}
model ProposalView {
id String @id @default(uuid())
proposalId String
sessionId String // Random UUID per session
viewedAt DateTime @default(now())
scrollDepth Int @default(0) // 0, 25, 50, 75, 100
timeOnPageSeconds Int @default(0)
ctaClicked Boolean @default(false)
expandedSections Json @default("[]") // Array of section IDs
userAgent String? @db.Text
referrer String? @db.Text
ipHash String? // SHA256 hash of IP for privacy
proposal Proposal @relation(fields: [proposalId], references: [id], onDelete: Cascade)
@@index([proposalId])
@@index([sessionId])
}
model ContactRequest {
id String @id @default(uuid())
proposalId String
name String
email String?
phone String?
bestTime String? // Dropdown value
preferredTier String? // starter, growth, premium
message String? @db.Text
createdAt DateTime @default(now())
proposal Proposal @relation(fields: [proposalId], references: [id], onDelete: Cascade)
@@index([proposalId])
}
model ProposalFollowUp {
id String @id @default(uuid())
proposalId String
tenantId String
type String // 'email' | 'reminder'
step Int // 1, 2, 3
status String // 'pending', 'sent', 'cancelled'
emailSubject String
emailBody String @db.Text
scheduledAt DateTime
sentAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
proposal Proposal @relation(fields: [proposalId], references: [id], onDelete: Cascade)
@@index([proposalId])
@@index([tenantId])
@@index([status])
@@index([scheduledAt])
}
model EvidenceSnapshot {
id String @id @default(uuid())
auditId String
module String
source String
rawResponse Json
collectedAt DateTime @default(now())
// Multi-Tenancy
tenantId String?
audit Audit @relation(fields: [auditId], references: [id], onDelete: Cascade)
@@index([auditId])
@@index([tenantId])
}
model ProposalTemplate {
id String @id @default(uuid())
name String
description String?
industry String?
isDefault Boolean @default(false)
// Custom Content
headerHtml String? @db.Text
introText String? @db.Text
outroText String? @db.Text
ctaText String?
ctaUrl String?
customCss String? @db.Text
footnotes String? @db.Text
// Toggles
showFindings Boolean @default(true)
showCompetitorMatrix Boolean @default(true)
showRoi Boolean @default(true)
// Standard Fields
assumptions String[] @default([])
disclaimers String[] @default([])
nextSteps String[] @default([])
pricing Json @default("{}")
tierSettings Json @default("{}") // Store tier-specific customizations
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Multi-Tenancy
tenantId String? // Global templates = null, Custom = tenantId
proposals Proposal[]
@@index([industry])
@@index([createdAt])
@@index([tenantId])
}
// Feature #8: Tiered Pricing
model User {
id String @id @default(uuid())
email String @unique
name String?
// NextAuth fields
emailVerified DateTime?
image String?
passwordHash String?
role String @default("member") // owner, admin, member, viewer
// Legacy or Personal Subscription
subscriptionTier SubscriptionTier @default(STARTER)
stripeCustomerId String? @unique
subscriptionId String? @unique
auditsThisMonth Int @default(0)
auditsLimit Int @default(10)
tenantId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
tenant Tenant? @relation(fields: [tenantId], references: [id])
accounts Account[]
sessions Session[]
@@index([email])
@@index([subscriptionTier])
@@index([tenantId])
}
// Feature #9: Multi-Tenant
model Tenant {
id String @id @default(uuid())
name String
slug String? @unique
domain String? @unique
// Billing
planTier String @default("free") // free, starter, pro, agency
status String @default("active") // active, trial, suspended
stripeCustomerId String?
stripeSubscriptionId String?
branding Json @default("{}")
settings Json @default("{}")
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
users User[]
audits Audit[]
brandingConfig TenantBranding?
apiKeys ApiKey[]
playbooks Playbook[]
auditSchedules AuditSchedule[]
UsageRecord UsageRecord[]
invitations Invitation[]
prospectDiscoveryJobs ProspectDiscoveryJob[]
prospectLeads ProspectLead[]
prospectEnrichmentRuns ProspectEnrichmentRun[]
outreachSendingDomains OutreachSendingDomain[]
outreachDomainDailyStats OutreachDomainDailyStat[]
outreachEmails OutreachEmail[]
outreachEmailEvents OutreachEmailEvent[]
pipelineConfig PipelineConfig?
projects Project[]
@@index([domain])
@@index([isActive])
}
model Invitation {
id String @id @default(uuid())
email String
role String @default("member")
token String @unique
tenantId String
invitedBy String?
expiresAt DateTime
acceptedAt DateTime?
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@index([tenantId])
@@index([token])
}
model Playbook {
id String @id @default(uuid())
tenantId String? // Null = System Default
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
industry String // e.g. "dental", "restaurant"
name String
description String?
// Configurations
moduleConfig Json @default("{}")
pricingConfig Json @default("{}")
promptOverrides Json @default("{}")
customFindings Json @default("[]")
proposalLanguage Json @default("{}")
isDefault Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([tenantId, industry]) // One playbook per industry per tenant
@@index([industry])
@@index([tenantId])
}
model AuditSchedule {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
businessName String
businessCity String?
businessUrl String?
industry String?
frequency String // 'weekly', 'biweekly', 'monthly', 'quarterly'
nextRunAt DateTime
lastRunAt DateTime?
lastAuditId String? // FK to last completed audit (optional relation/just string)
isActive Boolean @default(true)
createdBy String? // User ID
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([tenantId])
@@index([nextRunAt])
@@index([isActive])
}
// Target list for validation blitz / sales pipeline
model AuditTarget {
id String @id @default(uuid())
businessName String
businessCity String?
businessUrl String
placeId String?
phone String?
address String?
rating Float?
reviewCount Int?
category String?
vertical String // e.g. dentist, law-firm, hvac
source String @default("saskatoon-validation")
createdAt DateTime @default(now())
@@index([placeId])
@@index([vertical])
@@index([source])
}
model ProspectDiscoveryJob {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
city String
state String?
metro String?
vertical String
targetLeads Int @default(200)
painThreshold Int @default(60)
sourceConfig Json @default("{\"googlePlaces\":true,\"yelp\":true,\"directories\":true}")
status ProspectDiscoveryJobStatus @default(QUEUED)
runAttempts Int @default(0)
discoveredCount Int @default(0)
qualifiedCount Int @default(0)
enrichedCount Int @default(0)
lastError String?
nextRunAt DateTime @default(now())
startedAt DateTime?
completedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
leads ProspectLead[]
@@index([tenantId, status, nextRunAt])
@@index([city, vertical])
@@index([createdAt])
}
model ProspectLead {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
discoveryJobId String?
discoveryJob ProspectDiscoveryJob? @relation(fields: [discoveryJobId], references: [id], onDelete: SetNull)
source String
sourceExternalId String
sourceUrl String?
businessName String
city String
state String?
vertical String
category String?
address String?
phone String?
website String?
rating Float?
reviewCount Int?
status ProspectLeadStatus @default(DISCOVERED)
painScore Int?
painThreshold Int @default(60)
painBreakdown Json @default("{}")
topFindings Json @default("[]")
auditSummarySnippet String?
qualificationEvidence Json @default("{}")
qualifiedAt DateTime?
disqualifiedReason String?
decisionMakerName String?
decisionMakerTitle String?
decisionMakerLinkedin String?
decisionMakerEmail String?
decisionMakerEmailStatus String?
enrichmentState Json @default("{}")
estimatedCostCents Int @default(0)
outreachStage OutreachLeadStage @default(READY)
outreachAttempts Int @default(0)
outreachOpenCount Int @default(0)
outreachClickCount Int @default(0)
outreachReplyCount Int @default(0)
outreachLastContactedAt DateTime?
outreachNextActionAt DateTime?
outreachDroppedAt DateTime?
outreachDropReason String?
scorecardToken String? @unique
scorecardFirstViewedAt DateTime?
scorecardLastViewedAt DateTime?
scorecardTotalViewSeconds Int @default(0)
// Pipeline orchestrator fields
pipelineStatus String @default("discovered")
auditId String?
proposalId String?
engagementScore Int @default(0)
lastEngagementAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
enrichmentRuns ProspectEnrichmentRun[]
outreachEmails OutreachEmail[]
outreachEvents OutreachEmailEvent[]
stateTransitions ProspectStateTransition[]
deliveredLeads PartnerDeliveredLead[]
@@unique([tenantId, source, sourceExternalId])
@@index([tenantId, status])
@@index([city, vertical])
@@index([painScore])
@@index([discoveryJobId])
@@index([createdAt])
@@index([tenantId, outreachStage, outreachNextActionAt])
@@index([pipelineStatus])
@@index([engagementScore])
}
model ProspectEnrichmentRun {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
leadId String
lead ProspectLead @relation(fields: [leadId], references: [id], onDelete: Cascade)
provider ProspectEnrichmentProvider
status ProspectEnrichmentStatus @default(PENDING)
requestPayload Json @default("{}")
responsePayload Json @default("{}")
costCents Int @default(0)
errorMessage String?
startedAt DateTime @default(now())
completedAt DateTime?
createdAt DateTime @default(now())
@@index([tenantId, provider, status])
@@index([leadId, createdAt])
}
model OutreachSendingDomain {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
domain String
fromEmail String
fromName String?
dailyLimit Int @default(50)
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
emails OutreachEmail[]
dailyStats OutreachDomainDailyStat[]
@@unique([tenantId, fromEmail])
@@index([tenantId, isActive])
}
model OutreachDomainDailyStat {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
domainId String
domain OutreachSendingDomain @relation(fields: [domainId], references: [id], onDelete: Cascade)
day DateTime
sentCount Int @default(0)
openCount Int @default(0)
clickCount Int @default(0)
replyCount Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([domainId, day])
@@index([tenantId, day])
}
model OutreachEmail {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
leadId String
lead ProspectLead @relation(fields: [leadId], references: [id], onDelete: Cascade)
domainId String?
domain OutreachSendingDomain? @relation(fields: [domainId], references: [id], onDelete: SetNull)
type OutreachEmailType @default(INITIAL)
status OutreachEmailStatus @default(PENDING)
subject String
body String @db.Text
qualityScore Int @default(0)
readabilityGrade Float @default(0)
wordCount Int @default(0)
spamRisk Int @default(0)
findingsUsed Json @default("[]")
scorecardUrl String?
proposalUrl String?
trackingPixelUrl String?
trackingClickBaseUrl String?
providerMessageId String?
errorMessage String?
sentAt DateTime?
openedAt DateTime?
clickedAt DateTime?
repliedAt DateTime?
scheduledAt DateTime?
sequencePosition Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
events OutreachEmailEvent[]
@@index([tenantId, status, createdAt])
@@index([leadId, createdAt])
@@index([domainId, createdAt])
@@index([type, status])
@@index([scheduledAt, status])
}
model OutreachEmailEvent {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
leadId String
lead ProspectLead @relation(fields: [leadId], references: [id], onDelete: Cascade)
emailId String?
email OutreachEmail? @relation(fields: [emailId], references: [id], onDelete: SetNull)
type OutreachEventType
metadata Json @default("{}")
occurredAt DateTime @default(now())
createdAt DateTime @default(now())
@@index([tenantId, type, occurredAt])
@@index([leadId, occurredAt])
@@index([emailId, occurredAt])
}
model ApiKey {
id String @id @default(uuid())
tenantId String
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
keyHash String @unique
keyPrefix String
name String
scopes String[] // e.g. ["audit:create", "audit:read"]
isActive Boolean @default(true)
rateLimitPerDay Int @default(1000)
usageCount Int @default(0) // Track usage for the day
lastResetAt DateTime @default(now()) // Track when usage was last reset
lastUsedAt DateTime?
expiresAt DateTime?
createdAt DateTime @default(now())
@@index([tenantId])
@@index([keyHash])
}
model TenantBranding {
id String @id @default(uuid())
tenantId String @unique
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
brandName String?
tagline String?
logoUrl String?
logoDarkUrl String?
primaryColor String @default("#8B5CF6")
secondaryColor String @default("#38BDF8")
accentColor String @default("#F59E0B")
contactEmail String?
contactPhone String?
websiteUrl String?
// Custom Domain
customDomain String? @unique
customDomainVerified Boolean @default(false)
customDomainVerifiedAt DateTime?
footerText String?
showPoweredBy Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// NextAuth Models
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
// Prospect state transition history
model ProspectStateTransition {
id String @id @default(uuid())
tenantId String
leadId String
fromStatus String
toStatus String
stage String // Pipeline stage that triggered the transition
metadata Json @default("{}")
createdAt DateTime @default(now())
lead ProspectLead @relation(fields: [leadId], references: [id], onDelete: Cascade)
@@index([leadId, createdAt])
@@index([tenantId, createdAt])
}
// Delivery tasks for fulfilled proposals
model DeliveryTask {
id String @id @default(uuid())
tenantId String
proposalId String
findingId String
agentType String // 'speed_optimization', 'seo_fix', 'accessibility', 'security_hardening', 'content_generation'
status String @default("queued") // 'queued', 'in_progress', 'completed', 'verified', 'failed', 'escalated'
estimatedCompletionDate DateTime
completedAt DateTime?
verificationAuditId String?
beforeAfterComparison Json?
errorMessage String?
// Sprint 10: Delivery Agent fields
artifactId String? // FK to GeneratedArtifact
bundleId String? // FK to DeliveryBundle
confidenceLevel String? // 'HIGH', 'MEDIUM', 'LOW'
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([tenantId, status])
@@index([proposalId])
@@index([estimatedCompletionDate])
}
// Pipeline stage configuration per tenant
model PipelineConfig {
id String @id @default(uuid())
tenantId String @unique
concurrencyLimit Int @default(10)
batchSize Int @default(50)
painScoreThreshold Int @default(60)
dailyVolumeLimit Int @default(200)
spendingLimitCents Int @default(100000) // $1000 default
hotLeadPercentile Int @default(95)
emailMinQualityScore Int @default(90)
maxEmailsPerDomainPerDay Int @default(50)
// Follow-up schedule (days after initial send)
followUpSchedule Json @default("[3, 7, 14]")
// Stage-level pause flags
pausedStages Json @default("[]")
// Country/language config
country String @default("US")
language String @default("en")
currency String @default("USD")
// Pricing multiplier
pricingMultiplier Float @default(1.0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@index([tenantId])
}
// Pipeline error log for observability
model PipelineErrorLog {
id String @id @default(uuid())
tenantId String
stage String
prospectId String?
errorType String
errorMessage String @db.Text
stackTrace String? @db.Text
metadata Json @default("{}")
createdAt DateTime @default(now())
@@index([tenantId, stage, createdAt])
@@index([createdAt])
}
// Outreach template performance tracking
model OutreachTemplatePerformance {
id String @id @default(uuid())
templateId String
vertical String
city String?
totalSent Int @default(0)
openCount Int @default(0)
clickCount Int @default(0)
replyCount Int @default(0)
conversionCount Int @default(0)
openRate Float @default(0)
clickRate Float @default(0)
replyRate Float @default(0)
conversionRate Float @default(0)
updatedAt DateTime @updatedAt
@@unique([templateId, vertical, city])
@@index([vertical])
}
// Win/loss tracking with reason codes
model WinLossRecord {
id String @id @default(uuid())
tenantId String
proposalId String
leadId String
vertical String
city String?
outcome String // 'won', 'lost', 'ghosted'
tierChosen String?
dealValue Decimal? @db.Decimal(10, 2)
lostReason String?
objectionsRaised Json @default("[]")
competitorMentioned String?
createdAt DateTime @default(now())
@@index([tenantId, vertical, outcome])
@@index([createdAt])
}
// Pre-warming actions for multi-channel engagement
model PreWarmingAction {
id String @id @default(uuid())
tenantId String
leadId String
platform String // 'gbp', 'facebook', 'instagram'
actionType String // 'question', 'like', 'comment', 'follow', 'post_interaction'
status String @default("scheduled") // 'scheduled', 'completed', 'failed', 'skipped'
scheduledAt DateTime
executedAt DateTime?
errorMessage String?
createdAt DateTime @default(now())
@@index([tenantId, platform, scheduledAt])
@@index([leadId])
}
// Detected signals for signal-based selling
model DetectedSignal {
id String @id @default(uuid())
tenantId String
leadId String?
signalType String // 'bad_review', 'website_change', 'competitor_upgrade', 'new_business_license', 'hiring_spike'
priority String @default("medium") // 'high', 'medium', 'low'
sourceData Json @default("{}")
outreachTriggered Boolean @default(false)
outreachEmailId String?
detectedAt DateTime @default(now())
createdAt DateTime @default(now())
@@unique([tenantId, leadId, signalType, detectedAt])
@@index([tenantId, signalType, detectedAt])
@@index([leadId])
}
// AI Sales Chat conversations
model ChatConversation {
id String @id @default(uuid())
tenantId String
proposalId String
sessionId String
messages Json @default("[]") // Array of ChatMessage
outcome String? // 'converted', 'escalated', 'abandoned'
objections Json @default("[]") // Array of objection strings
startedAt DateTime @default(now())
completedAt DateTime?
@@index([tenantId, proposalId])
@@index([sessionId])
}
// Agency partner accounts
model AgencyPartner {
id String @id @default(uuid())
name String
contactEmail String
contactName String?
verticals Json @default("[]") // Array of target verticals
geographies Json @default("[]") // Array of target geographies