// 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 pets (\n  id TEXT PRIMARY KEY,\n  owner_id TEXT REFERENCES users(id),\n  name TEXT NOT NULL,\n  species TEXT,\n  breed TEXT,\n  birth_date TEXT,\n  weight_kg REAL,\n  avatar_url TEXT,\n  created_at TEXT\n);",
  "CREATE TABLE IF NOT EXISTS schedules (\n  id TEXT PRIMARY KEY,\n  pet_id TEXT REFERENCES pets(id),\n  type TEXT NOT NULL,\n  title TEXT NOT NULL,\n  scheduled_at TEXT,\n  completed INTEGER DEFAULT false\n);",
  "CREATE TABLE IF NOT EXISTS daily_logs (\n  id TEXT PRIMARY KEY,\n  pet_id TEXT REFERENCES pets(id),\n  category TEXT NOT NULL,\n  value TEXT,\n  logged_at TEXT\n);"
  ];
  for (const sql of statements) {
    const trimmed = sql.trim();
    if (trimmed) db.run(trimmed);
  }
}
