-- The Small Business MBA. Lesson resources (workbooks, tools, worksheets, guides).
-- Each resource is REBUILT on-brand (stored as brand HTML), never the raw source file.
-- A lesson (module) can have several. Shown in the lesson reader's "Resources & Downloads"
-- panel, viewable and printable. Re-import replaces a lesson's resources wholesale.

CREATE TABLE IF NOT EXISTS lesson_resources (
  id         TEXT PRIMARY KEY,
  lesson_id  TEXT NOT NULL REFERENCES lessons(id) ON DELETE CASCADE,
  sort       INTEGER NOT NULL DEFAULT 0,
  type       TEXT NOT NULL DEFAULT 'worksheet',  -- worksheet | workbook | tool | guide | template
  title      TEXT NOT NULL,
  body_html  TEXT NOT NULL,
  created_at INTEGER NOT NULL,
  updated_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_lesson_resources_lesson ON lesson_resources(lesson_id);
