-- Phase 6: Lesson plans — structured curriculum per enrollment

CREATE TYPE "lesson_plan_item_status" AS ENUM ('not_started', 'in_progress', 'mastered', 'skipped');

CREATE TABLE "member_lesson_plan" (
  "id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  "member_id" uuid NOT NULL REFERENCES "member"("id"),
  "enrollment_id" uuid NOT NULL REFERENCES "enrollment"("id"),
  "created_by" uuid REFERENCES "user"("id"),
  "title" varchar(255) NOT NULL,
  "description" text,
  "is_active" boolean NOT NULL DEFAULT true,
  "started_date" date,
  "completed_date" date,
  "created_at" timestamptz NOT NULL DEFAULT now(),
  "updated_at" timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE "lesson_plan_section" (
  "id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  "lesson_plan_id" uuid NOT NULL REFERENCES "member_lesson_plan"("id"),
  "title" varchar(255) NOT NULL,
  "description" text,
  "sort_order" integer NOT NULL,
  "created_at" timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE "lesson_plan_item" (
  "id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  "section_id" uuid NOT NULL REFERENCES "lesson_plan_section"("id"),
  "title" varchar(255) NOT NULL,
  "description" text,
  "status" lesson_plan_item_status NOT NULL DEFAULT 'not_started',
  "grading_scale_id" uuid REFERENCES "grading_scale"("id"),
  "current_grade_value" varchar(50),
  "target_grade_value" varchar(50),
  "started_date" date,
  "mastered_date" date,
  "notes" text,
  "sort_order" integer NOT NULL,
  "created_at" timestamptz NOT NULL DEFAULT now(),
  "updated_at" timestamptz NOT NULL DEFAULT now()
);
