#!/bin/bash
# Export all daily verses to JSON
# Usage: ./export-verses.sh [path/to/database.db] [output.json]

DB="${1:-./local.db}"
OUT="${2:-verses.json}"

sqlite3 "$DB" <<'SQL' > "$OUT"
.mode json
SELECT
  CASE book_id
    WHEN 'GEN' THEN 'Genesis'
    WHEN 'EXO' THEN 'Exodus'
    WHEN 'LEV' THEN 'Leviticus'
    WHEN 'NUM' THEN 'Numbers'
    WHEN 'DEU' THEN 'Deuteronomy'
    WHEN 'JOS' THEN 'Joshua'
    WHEN 'JDG' THEN 'Judges'
    WHEN 'RUT' THEN 'Ruth'
    WHEN '1SA' THEN '1 Samuel'
    WHEN '2SA' THEN '2 Samuel'
    WHEN '1KI' THEN '1 Kings'
    WHEN '2KI' THEN '2 Kings'
    WHEN '1CH' THEN '1 Chronicles'
    WHEN '2CH' THEN '2 Chronicles'
    WHEN 'EZR' THEN 'Ezra'
    WHEN 'NEH' THEN 'Nehemiah'
    WHEN 'EST' THEN 'Esther'
    WHEN 'JOB' THEN 'Job'
    WHEN 'PSA' THEN 'Psalms'
    WHEN 'PRO' THEN 'Proverbs'
    WHEN 'ECC' THEN 'Ecclesiastes'
    WHEN 'SNG' THEN 'Song of Solomon'
    WHEN 'ISA' THEN 'Isaiah'
    WHEN 'JER' THEN 'Jeremiah'
    WHEN 'LAM' THEN 'Lamentations'
    WHEN 'EZK' THEN 'Ezekiel'
    WHEN 'DAN' THEN 'Daniel'
    WHEN 'HOS' THEN 'Hosea'
    WHEN 'JOL' THEN 'Joel'
    WHEN 'AMO' THEN 'Amos'
    WHEN 'OBA' THEN 'Obadiah'
    WHEN 'JON' THEN 'Jonah'
    WHEN 'MIC' THEN 'Micah'
    WHEN 'NAM' THEN 'Nahum'
    WHEN 'HAB' THEN 'Habakkuk'
    WHEN 'ZEP' THEN 'Zephaniah'
    WHEN 'HAG' THEN 'Haggai'
    WHEN 'ZEC' THEN 'Zechariah'
    WHEN 'MAL' THEN 'Malachi'
    WHEN 'MAT' THEN 'Matthew'
    WHEN 'MRK' THEN 'Mark'
    WHEN 'LUK' THEN 'Luke'
    WHEN 'JHN' THEN 'John'
    WHEN 'ACT' THEN 'Acts'
    WHEN 'ROM' THEN 'Romans'
    WHEN '1CO' THEN '1 Corinthians'
    WHEN '2CO' THEN '2 Corinthians'
    WHEN 'GAL' THEN 'Galatians'
    WHEN 'EPH' THEN 'Ephesians'
    WHEN 'PHP' THEN 'Philippians'
    WHEN 'COL' THEN 'Colossians'
    WHEN '1TH' THEN '1 Thessalonians'
    WHEN '2TH' THEN '2 Thessalonians'
    WHEN '1TI' THEN '1 Timothy'
    WHEN '2TI' THEN '2 Timothy'
    WHEN 'TIT' THEN 'Titus'
    WHEN 'PHM' THEN 'Philemon'
    WHEN 'HEB' THEN 'Hebrews'
    WHEN 'JAS' THEN 'James'
    WHEN '1PE' THEN '1 Peter'
    WHEN '2PE' THEN '2 Peter'
    WHEN '1JN' THEN '1 John'
    WHEN '2JN' THEN '2 John'
    WHEN '3JN' THEN '3 John'
    WHEN 'JUD' THEN 'Jude'
    WHEN 'REV' THEN 'Revelation'
    ELSE book_id
  END AS book,
  verse_text AS verse,
  reference  AS citation,
  date
FROM daily_verses
ORDER BY date;
SQL

echo "Exported to $OUT"
