export interface User {
  id: string;
  firstName: string;
  lastName: string;
  email: string;
  country: string;
  phone: string;
  company: string;
  website?: string;
  passwordHash: string;
  planId: PlanId;
  pagesRemaining: number;
  domains: string[];
  createdAt: string;
  /** Stripe Customer id (users.stripe_customer_id) — set on first Stripe payment. */
  stripeCustomerId?: string;
}

export type PlanId = 'free' | 'small' | 'medium' | 'large' | 'xlarge';

export interface Plan {
  id: PlanId;
  name: string;
  pages: number;
  price: number;
  originalPrice: number;
  perPage: number;
  description: string;
  packageId?: number; // package_details.id (DB row), used for user_packages entries
}

// 'url' = manually added via "Scan PDF URL" (Upload tab); 'web' = discovered by
// the Website Scan crawler — kept distinct so the two tabs never mix records.
export type DocumentSource = 'file' | 'url' | 'web';

export type DocumentStatus =
  | 'pending_scan' // URL added, not scanned yet
  | 'scanning' // URL scan in progress
  | 'ready' // uploaded / scanned, ready to remediate
  | 'processing' // remediation in progress
  | 'remediated' // done
  | 'error';

export interface PdfDocument {
  id: string;
  userId: string;
  name: string;
  source: DocumentSource;
  sourceUrl?: string;
  /** Which of the user's own domains a crawler-discovered ('web') document came from. */
  domain?: string;
  status: DocumentStatus;
  pages: number;
  sizeBytes: number;
  storagePath?: string;
  remediatedPath?: string;
  remediatedName?: string;
  remediatedPages?: number; // pages actually remediated (partial trial runs)
  remediatedAt?: string;
  createdAt: string;
}

export interface RemediationJob {
  id: string;
  userId: string;
  documentIds: string[];
  totalPages: number; // pages being remediated in this job
  progress: number; // 0..100
  status: 'processing' | 'completed';
  partial: boolean;
  createdAt: string;
  completedAt?: string;
}

export interface Order {
  id: string;
  userId: string;
  planId: PlanId;
  amount: number;
  billing: Record<string, string>;
  cardLast4: string;
  createdAt: string;
}

export interface OutboxEmail {
  id: string;
  userId: string;
  to: string;
  subject: string;
  template: 'trial-result' | 'remediation-complete' | 'welcome' | 'invoice' | 'password-reset';
  file: string;
  createdAt: string;
}

export interface Database {
  users: User[];
  documents: PdfDocument[];
  jobs: RemediationJob[];
  orders: Order[];
  emails: OutboxEmail[];
}
