Spaces:
Running

File size: 2,866 Bytes
727ec8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d33ce6
727ec8d
 
 
 
 
 
 
 
 
 
 
 
 
1d33ce6
 
 
 
 
 
 
 
 
 
 
727ec8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Notification models for HOT lead alerts.

Focus: Save time by notifying only about ready-to-buy leads.
"""

from typing import Optional
from datetime import datetime
from uuid import UUID, uuid4
from sqlmodel import SQLModel, Field, Relationship


class NotificationSettings(SQLModel, table=True):
    """
    Notification settings for each tenant.
    
    Controls how and when to send notifications about HOT leads.
    """
    __tablename__ = "notification_settings"
    
    id: UUID = Field(default_factory=uuid4, primary_key=True)
    tenant_id: UUID = Field(foreign_key="tenants.id", unique=True, index=True)
    
    # Telegram Settings
    telegram_enabled: bool = Field(default=True)
    telegram_chat_id: Optional[str] = Field(default=None)
    telegram_channel_id: Optional[str] = Field(default=None) # Public/Team Channel
    telegram_bot_token: Optional[str] = Field(default=None)  # Optional: custom bot
    
    # Dashboard Settings
    dashboard_enabled: bool = Field(default=True)
    
    # Email Settings (for future)
    email_enabled: bool = Field(default=False)
    email_address: Optional[str] = Field(default=None)
    
    # Notification Types
    notify_hot_leads: bool = Field(default=True)  # Main focus!
    notify_inactive_leads: bool = Field(default=False)
    notify_new_leads: bool = Field(default=False)
    
    # Granular Settings
    notify_orders: bool = Field(default=True)
    notify_bookings: bool = Field(default=True)
    notify_qualification_complete: bool = Field(default=True)
    
    # Escalation Settings (Traffic Light)
    notify_escalations: bool = Field(default=True)  # Master switch
    notify_escalation_high: bool = Field(default=True) # Red (Anger, Request Human)
    notify_escalation_medium: bool = Field(default=True) # Yellow (Complex, Low Conf)
    notify_escalation_low: bool = Field(default=False) # Green (Info)
    
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow)


class Notification(SQLModel, table=True):
    """
    Notification record for Dashboard display.
    
    Stores all notifications sent to tenant (HOT leads, etc.)
    """
    __tablename__ = "notifications"
    
    id: UUID = Field(default_factory=uuid4, primary_key=True)
    tenant_id: UUID = Field(foreign_key="tenants.id", index=True)
    lead_id: UUID = Field(foreign_key="leads.id")
    
    # Notification Details
    type: str = Field(index=True)  # "hot_lead", "inactive", etc.
    title: str
    message: str
    
    # Status
    is_read: bool = Field(default=False, index=True)
    read_at: Optional[datetime] = Field(default=None)
    
    # Channels
    sent_telegram: bool = Field(default=False)
    sent_dashboard: bool = Field(default=True)
    
    created_at: datetime = Field(default_factory=datetime.utcnow, index=True)