export type UserRole = 'admin' | 'agent' | 'buyer';

export interface User {
  id: string;
  email: string;
  role: UserRole;
  name: string;
  company?: string;
  phone?: string;
  avatar_url?: string;
  password_hash?: string;
  created_at: string;
  updated_at: string;
}

export type AssetType =
  | 'Office'
  | 'Industrial'
  | 'Retail'
  | 'Multifamily'
  | 'Mixed-Use'
  | 'Land'
  | 'Hospitality'
  | 'Other';

export type LeadStatus = 'active' | 'pending' | 'matched' | 'closed' | 'withdrawn';

export interface SellerLead {
  id: string;
  agent_id: string;
  address: string;
  asset_type: AssetType;
  asking_price: number;
  cap_rate: number;
  noi: number;
  sqft: number;
  units?: number;
  year_built?: number;
  market: string;
  city?: string;
  state?: string;
  notes?: string;
  status: LeadStatus;
  created_at: string;
  updated_at: string;
}

export interface SellerDocument {
  id: string;
  lead_id: string;
  file_url: string;
  file_name: string;
  file_type: string;
  file_size?: number;
  created_at: string;
}

export type BuyerStatus = 'active' | 'unresponsive' | 'high-intent' | 'inactive';

export interface Buyer {
  id: string;
  agent_id: string;
  user_id?: string;
  name: string;
  company?: string;
  email: string;
  phone?: string;
  asset_types: AssetType[];
  target_locations: string[];
  price_min?: number;
  price_max?: number;
  cap_rate_min?: number;
  cap_rate_max?: number;
  preferences?: string;
  status: BuyerStatus;
  engagement_score: number;
  last_contacted_at?: string;
  created_at: string;
  updated_at: string;
}

export type MatchStatus = 'pending' | 'approved' | 'sent' | 'interested' | 'passed' | 'closed';

export interface Match {
  id: string;
  lead_id: string;
  buyer_id: string;
  match_score: number;
  status: MatchStatus;
  agent_notes?: string;
  created_at: string;
  updated_at: string;
  // Joined data
  seller_lead?: SellerLead;
  buyer?: Buyer;
}

export type OutreachChannel = 'email' | 'sms';
export type OutreachStatus =
  | 'draft'
  | 'queued'
  | 'sent'
  | 'delivered'
  | 'opened'
  | 'clicked'
  | 'replied'
  | 'bounced'
  | 'failed';

export interface Outreach {
  id: string;
  match_id: string;
  channel: OutreachChannel;
  subject?: string;
  body: string;
  status: OutreachStatus;
  sent_at?: string;
  delivered_at?: string;
  opened_at?: string;
  clicked_at?: string;
  replied_at?: string;
  created_at: string;
  // Joined data
  match?: Match;
}

export interface NDA {
  id: string;
  buyer_id: string;
  lead_id: string;
  signer_name: string;
  signer_email: string;
  signer_company?: string;
  signed_at: string;
  ip_address?: string;
  created_at: string;
}

export type SubscriptionStatus = 'active' | 'inactive' | 'past_due' | 'canceled' | 'trialing';

export interface Subscription {
  id: string;
  user_id: string;
  stripe_customer_id?: string;
  stripe_subscription_id?: string;
  status: SubscriptionStatus;
  plan: string;
  current_period_start?: string;
  current_period_end?: string;
  cancel_at_period_end: boolean;
  created_at: string;
  updated_at: string;
}

export interface MatchResult {
  buyer: Buyer;
  score: number;
  breakdown: {
    assetTypeScore: number;
    locationScore: number;
    priceScore: number;
    capRateScore: number;
  };
}

export interface DashboardStats {
  activeDeals: number;
  totalBuyers: number;
  matchesMade: number;
  outreachSent: number;
  responseRate: number;
  dealsClosedThisMonth: number;
}
