""" 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)