// 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  phone TEXT UNIQUE,\n  nickname TEXT,\n  avatar_url TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_users_phone ON users(phone)",
  "CREATE TABLE IF NOT EXISTS boards (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  title TEXT NOT NULL,\n  description TEXT,\n  status TEXT DEFAULT 'active',\n  data TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_boards_user ON boards(user_id)",
  "CREATE TABLE IF NOT EXISTS tasks (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  title TEXT NOT NULL,\n  description TEXT,\n  status TEXT DEFAULT 'active',\n  data TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_tasks_user ON tasks(user_id)",
  "CREATE TABLE IF NOT EXISTS members (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  title TEXT NOT NULL,\n  description TEXT,\n  status TEXT DEFAULT 'active',\n  data TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_members_user ON members(user_id)",
  "CREATE TABLE IF NOT EXISTS items (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  title TEXT NOT NULL,\n  description TEXT,\n  status TEXT DEFAULT 'active',\n  data TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_items_user ON items(user_id)",
  "CREATE TABLE IF NOT EXISTS activity_logs (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  title TEXT NOT NULL,\n  description TEXT,\n  status TEXT DEFAULT 'active',\n  data TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_activity_logs_user ON activity_logs(user_id)",
  "CREATE TABLE IF NOT EXISTS stats (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  user_id TEXT REFERENCES users(id),\n  title TEXT NOT NULL,\n  description TEXT,\n  status TEXT DEFAULT 'active',\n  data TEXT,\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_stats_user ON stats(user_id)",
  "CREATE TABLE IF NOT EXISTS notes (\n  id TEXT PRIMARY KEY,\n  user_id TEXT REFERENCES users(id),\n  title TEXT,\n  content TEXT,\n  is_markdown INTEGER DEFAULT false,\n  folder_id TEXT REFERENCES folders(id),\n  created_at TEXT,\n  updated_at TEXT\n);",
  "idx_notes_user ON notes(user_id)",
  "idx_notes_folder ON notes(folder_id)",
  "idx_notes_fts ON notes USING GIN (to_tsvector('simple', title || ' ' || content))",
  "CREATE TABLE IF NOT EXISTS tags (\n  id TEXT PRIMARY KEY,\n  name TEXT NOT NULL UNIQUE,\n  color TEXT\n);",
  "CREATE TABLE IF NOT EXISTS note_tags (\n  note_id TEXT REFERENCES notes(id),\n  tag_id TEXT REFERENCES tags(id)\n);"
  ];
  for (const sql of statements) {
    const trimmed = sql.trim();
    if (trimmed) db.run(trimmed);
  }
}
