// Auto-generated SQLite schema
import type { Database } from "sql.js";

export function createTables(db: Database): void {
  const statements = [
  "CREATE TABLE IF NOT EXISTS users (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  username TEXT NOT NULL UNIQUE,\n  password_hash TEXT NOT NULL,\n  nickname TEXT,\n  role TEXT DEFAULT 'user',\n  phone TEXT,\n  avatar_url TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "CREATE TABLE IF NOT EXISTS customers (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  name TEXT NOT NULL,\n  email TEXT,\n  phone TEXT,\n  company TEXT,\n  source TEXT,\n  tags TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "CREATE TABLE IF NOT EXISTS sales_pipeline (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  customer_id TEXT REFERENCES customers(id),\n  stage TEXT NOT NULL,\n  amount REAL,\n  probability INTEGER,\n  expected_close TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "CREATE TABLE IF NOT EXISTS follow_ups (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  customer_id TEXT REFERENCES customers(id),\n  type TEXT,\n  content TEXT,\n  next_action TEXT,\n  next_action_date TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "CREATE TABLE IF NOT EXISTS dashboard (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  name TEXT NOT NULL,\n  description TEXT,\n  color TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);"
  ];
  for (const sql of statements) {
    const trimmed = sql.trim();
    if (trimmed) db.run(trimmed);
  }
}
