-- Per-user-per-assignment completion (textbook reading, future file-read, etc.)
-- Used to mark non-test assignments as done.
CREATE TABLE assignment_completion (
  assignment_id INTEGER NOT NULL REFERENCES assignments(id) ON DELETE CASCADE,
  user_id       INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  completed_at  TEXT    NOT NULL DEFAULT (datetime('now')),
  PRIMARY KEY (assignment_id, user_id)
);

-- Bookmarks/highlights inside textbooks (one row per highlight)
CREATE TABLE textbook_bookmarks (
  id          INTEGER PRIMARY KEY AUTOINCREMENT,
  user_id     INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  textbook_id INTEGER NOT NULL REFERENCES textbooks(id) ON DELETE CASCADE,
  para        TEXT,                            -- 'p15' (paragraph anchor, optional)
  text        TEXT NOT NULL,                   -- highlighted text snippet (max 400 chars)
  note        TEXT NOT NULL DEFAULT '',        -- user's comment
  color       TEXT NOT NULL DEFAULT 'yellow',  -- 'yellow','green','blue','pink'
  created_at  TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX idx_textbook_bookmarks_user      ON textbook_bookmarks (user_id, textbook_id);
CREATE INDEX idx_textbook_bookmarks_textbook  ON textbook_bookmarks (textbook_id);
