// 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 books (\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_books_user ON books(user_id)",
  "CREATE TABLE IF NOT EXISTS reading_status (\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_reading_status_user ON reading_status(user_id)",
  "CREATE TABLE IF NOT EXISTS reading_progress (\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_reading_progress_user ON reading_progress(user_id)",
  "CREATE TABLE IF NOT EXISTS notes (\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_notes_user ON notes(user_id)",
  "CREATE TABLE IF NOT EXISTS reviews (\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_reviews_user ON reviews(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 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 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);
  }
}
