CREATE TYPE "public"."consent_procedure_status" AS ENUM('draft', 'published', 'archived');--> statement-breakpoint
CREATE TYPE "public"."course_resource_type" AS ENUM('pdf', 'poster', 'slide_deck', 'article', 'link', 'image', 'video', 'other');--> statement-breakpoint
CREATE TYPE "public"."question_difficulty" AS ENUM('Easy', 'Medium', 'Hard');--> statement-breakpoint
CREATE TYPE "public"."question_status" AS ENUM('draft', 'published', 'archived');--> statement-breakpoint
CREATE TABLE "consentiq_procedures" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"slug" text NOT NULL,
	"name" text NOT NULL,
	"region" text DEFAULT '' NOT NULL,
	"approx_duration_min" integer DEFAULT 0 NOT NULL,
	"anaesthesia" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"summary" text DEFAULT '' NOT NULL,
	"involves" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"options" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"risks" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"benefits" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"alternatives" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"recovery" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"warnings" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"status" "consent_procedure_status" DEFAULT 'draft' NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "course_resources" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"course_id" uuid NOT NULL,
	"lesson_id" uuid,
	"type" "course_resource_type" DEFAULT 'link' NOT NULL,
	"title" text NOT NULL,
	"description" text DEFAULT '' NOT NULL,
	"url" text NOT NULL,
	"file_size" integer,
	"mime_type" text,
	"position" integer DEFAULT 0 NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "orthoprep_questions" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"number" integer DEFAULT 0 NOT NULL,
	"part" text DEFAULT '' NOT NULL,
	"chapter" text DEFAULT '' NOT NULL,
	"stem" text NOT NULL,
	"options" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"answer" text DEFAULT 'A' NOT NULL,
	"explanation" text DEFAULT '' NOT NULL,
	"distractors" text DEFAULT '' NOT NULL,
	"take_home" text DEFAULT '' NOT NULL,
	"difficulty" "question_difficulty" DEFAULT 'Medium' NOT NULL,
	"tags" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"status" "question_status" DEFAULT 'draft' NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "research_studies" ADD COLUMN "is_recruiting_collaborators" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "research_studies" ADD COLUMN "collaboration_email" text;--> statement-breakpoint
ALTER TABLE "research_studies" ADD COLUMN "authorship_opportunities" text DEFAULT '' NOT NULL;--> statement-breakpoint
ALTER TABLE "research_studies" ADD COLUMN "open_roles" jsonb DEFAULT '[]'::jsonb NOT NULL;--> statement-breakpoint
ALTER TABLE "course_resources" ADD CONSTRAINT "course_resources_course_id_courses_id_fk" FOREIGN KEY ("course_id") REFERENCES "public"."courses"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "course_resources" ADD CONSTRAINT "course_resources_lesson_id_lessons_id_fk" FOREIGN KEY ("lesson_id") REFERENCES "public"."lessons"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "consentiq_procedures_slug_idx" ON "consentiq_procedures" USING btree ("slug");--> statement-breakpoint
CREATE INDEX "consentiq_procedures_status_idx" ON "consentiq_procedures" USING btree ("status");--> statement-breakpoint
CREATE INDEX "consentiq_procedures_region_idx" ON "consentiq_procedures" USING btree ("region");--> statement-breakpoint
CREATE INDEX "course_resources_course_idx" ON "course_resources" USING btree ("course_id");--> statement-breakpoint
CREATE INDEX "course_resources_lesson_idx" ON "course_resources" USING btree ("lesson_id");--> statement-breakpoint
CREATE UNIQUE INDEX "orthoprep_questions_number_idx" ON "orthoprep_questions" USING btree ("number");--> statement-breakpoint
CREATE INDEX "orthoprep_questions_status_idx" ON "orthoprep_questions" USING btree ("status");--> statement-breakpoint
CREATE INDEX "orthoprep_questions_part_idx" ON "orthoprep_questions" USING btree ("part");