// Navigation Module Types
export type ModuleId = 'dashboard' | 'oracle' | 'sentinel' | 'inventory' | 'settings' | 'catalyst' | 'admin' | 'crm' | 'comms';
export type SentinelSubTab = 'overview' | 'live-session';


export interface NavItem {
  id: ModuleId;
  label: string;
  icon: string;
  description: string;
}

// User Types
export interface User {
  id: string;
  name: string;
  fullName?: string;
  email?: string;
  avatar?: string;
  role: string;
}

// Chat Types for Oracle
export interface ChatMessage {
  id: string;
  sender: 'user' | 'oracle';
  content: string;
  timestamp: Date;
  isThinking?: boolean;
}

export interface Lead {
  id: string;
  name: string;
  phone: string;
  source: 'whatsapp' | 'website' | 'walkin';
  status: 'new' | 'engaged' | 'qualified' | 'hot' | 'closed';
  lastMessage: string;
  lastActive: Date;
  unreadCount: number;
  avatar?: string;
  qualification: 'whale' | 'potential' | 'tire_kicker';
  budget?: string;
  interest?: string;
  /** Quantum Dynamics score 1-100, updated by NemoClaw in real-time */
  quantumDynamicsScore?: number;
  /** CRM intelligence tags e.g. ['HNI', 'NRI', 'Hot Lead'] */
  tags?: string[];
  /** Assigned broker user id */
  assignedTo?: string;
}

// Biometric Types for Sentinel
export interface Visitor {
  id: string;
  faceId: string;
  sentiment: 'excited' | 'interested' | 'neutral' | 'confused' | 'disinterested';
  confidence: number;
  dwellTime: number;
  zone: string;
  timestamp: Date;
}

export interface ZoneData {
  id: string;
  name: string;
  visitorCount: number;
  avgSentiment: number;
  heatmap: number[][];
}

// Dashboard Types
export interface DashboardMetrics {
  activeVisitors: number;
  todayLeads: number;
  closedDeals: number;
  conversionRate: number;
  sentiment: number;
  systemHealth: {
    cpu: number;
    gpu: number;
    memory: number;
    temperature: number;
  };
}

export interface LeadVelocityData {
  time: string;
  generated: number;
  closed: number;
}

// Inventory Types
export interface Unit {
  id: string;
  unitNumber: string;
  type: 'studio' | '1br' | '2br' | '3br' | 'penthouse';
  floor: number;
  area: number;
  price: number;
  status: 'available' | 'reserved' | 'sold' | 'hold';
  view: string;
  lastUpdated: Date;
}

// System Status
export interface SystemStatus {
  isConnected: boolean;
  serverStatus: 'online' | 'offline' | 'syncing';
  lastSync: Date;
  version: string;
}

// Journey River Types (Sentinel)
export interface JourneyEvent {
  id: string;
  type: 'call' | 'visit' | 'chat' | 'negotiation';
  timestamp: string;
  sentimentScore: number; // 0–100, determines X position on the river
  title: string;
  summary: string;
  aiInsight?: string;
  evidenceLabel?: string;
}

export interface JourneyClient {
  id: string;
  name: string;
  initials: string;
  stage: string;
  overallScore: number;
  events: JourneyEvent[];
}

// ── Catalyst Types (Meta Marketing Agency Module) ───────────────────────────

export type CampaignObjective =
  | 'OUTCOME_LEADS'
  | 'OUTCOME_SALES'
  | 'OUTCOME_AWARENESS'
  | 'OUTCOME_TRAFFIC'
  | 'OUTCOME_ENGAGEMENT';

export type CampaignStatus = 'ACTIVE' | 'PAUSED' | 'DELETED' | 'ARCHIVED';

export interface Campaign {
  id: string;
  name: string;
  objective: CampaignObjective;
  status: CampaignStatus;
  dailyBudget: number; // in cents (Meta format)
  lifetimeSpend: number;
  impressions: number;
  clicks: number;
  ctr: number; // percentage
  cpa: number; // cost per acquisition
  roi: number; // percentage
  createdAt: Date;
  updatedAt: Date;
}

export type AssetType = 'image' | 'video';
export type AssetStatus = 'queued' | 'rendering' | 'ready' | 'uploaded' | 'failed';

export interface MarketingAsset {
  id: string;
  name: string;
  type: AssetType;
  status: AssetStatus;
  renderMessage?: string; // e.g. "Wan 2.2 is rendering cinematic lighting..."
  localUrl?: string; // ComfyUI output path
  metaAssetId?: string; // Meta Ad Library ID after upload
  thumbnailUrl?: string;
  language?: 'en' | 'ar';
  createdAt: Date;
}

export interface AdInsight {
  adSetId: string;
  adSetName: string;
  spend: number;
  impressions: number;
  clicks: number;
  ctr: number;
  cpa: number;
  roi: number;
  date: string; // ISO date string
}

export type LiveEventType = 'pause' | 'shift' | 'create' | 'optimize' | 'alert' | 'rotate';

export interface LiveOptimizationEvent {
  id: string;
  type: LiveEventType;
  message: string;
  campaignName?: string;
  timestamp: Date;
  value?: string; // e.g. CPA amount, budget shift amount
}

export interface CatalystSettings {
  metaAccessToken: string;
  metaAdAccountId: string;
  metaBusinessId: string;
  metaAppId: string;
  whatsappPhoneNumberId: string;
  isConnected: boolean;
}

// ── Sentinel Quantum Dynamics Types ──────────────────────────────────────────

/**
 * Compact biometric packet emitted by PerceptionPlayer every 500ms.
 * Contains MediaPipe blend shape coefficients (52 values, 0-1 range)
 * plus the exact video playback timestamp for stimulus correlation.
 */
export interface BiometricPacket {
  person_id?: string;
  lead_id?: string;
  canonical_lead_id?: string;
  session_id: string;
  session_mode?: 'assigned' | 'auto';
  video_asset_id?: string;
  /** Milliseconds into the currently-playing marketing video */
  video_ts_ms: number;
  /** MediaPipe FaceLandmarker blend shape coefficients */
  blend_shapes: Record<string, number>;
}

/** Emitted by FastAPI after NemoClaw processes a biometric packet batch */
export interface QDScoreUpdate {
  person_id?: string;
  lead_id?: string;
  session_id?: string;
  qd_score: number;
  delta: number;
  reasoning?: string;
  timestamp: string;
}

/** Velocity Link opened event received over WebSocket */
export interface VaultOpenedEvent {
  lead_id: string;
  lead_name: string;
  asset_name: string;
  tracking_hash: string;
  opened_at: string;
  ip?: string;
}

// ── Active Notification Center Types ──────────────────────────────────────────

export type NotificationType =
  | 'velocity_link_opened'
  | 'qd_spike'
  | 'lead_tagged'
  | 'system';

export interface VelocityNotification {
  id: string;
  type: NotificationType;
  title: string;
  body: string;
  leadId?: string;
  /** Current QD score for qd_spike events */
  qdScore?: number;
  /** Tags added for lead_tagged events */
  tags?: string[];
  timestamp: Date;
  isRead: boolean;
}

// ── Velocity Vault Types ───────────────────────────────────────────────────────

export interface VaultAsset {
  id: string;
  asset_name: string;
  asset_type: 'pdf' | 'image' | 'video';
  tracking_hash: string;
  vault_url: string;
  lead_id: string;
  created_at: string;
  opened_count: number;
}

export interface GenerateLinkRequest {
  lead_id: string;
  asset_name: string;
  asset_type: 'pdf' | 'image' | 'video';
  storage_path: string;
}

export interface GenerateLinkResponse {
  tracking_hash: string;
  vault_url: string;
  asset_id: string;
}

export interface MarketingVideo {
  id: string;
  title: string;
  property_name: string;
  unit_number: string;
  type: string;
  duration_seconds: number;
  video_url: string;
  thumbnail_color: string;
}
