-- CreateEnum
CREATE TYPE "classroom_activity_tone" AS ENUM ('DANGER', 'SUCCESS', 'PRIMARY', 'WARNING');

-- CreateTable
CREATE TABLE "classroom_activities" (
    "id" TEXT NOT NULL,
    "tenant_id" TEXT NOT NULL,
    "classroom_id" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "starts_on" DATE NOT NULL,
    "ends_on" DATE NOT NULL,
    "tone" "classroom_activity_tone" NOT NULL DEFAULT 'PRIMARY',
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by_user_id" TEXT,

    CONSTRAINT "classroom_activities_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "classroom_activities_date_range_chk" CHECK ("ends_on" >= "starts_on")
);

-- CreateIndex
CREATE INDEX "classroom_activities_tenant_id_classroom_id_starts_on_idx" ON "classroom_activities"("tenant_id", "classroom_id", "starts_on");

-- CreateIndex
CREATE INDEX "classroom_activities_tenant_id_starts_on_idx" ON "classroom_activities"("tenant_id", "starts_on");

-- CreateIndex
CREATE INDEX "classroom_activities_classroom_id_starts_on_idx" ON "classroom_activities"("classroom_id", "starts_on");

-- AddForeignKey
ALTER TABLE "classroom_activities" ADD CONSTRAINT "classroom_activities_tenant_id_fkey" FOREIGN KEY ("tenant_id") REFERENCES "tenants"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "classroom_activities" ADD CONSTRAINT "classroom_activities_classroom_id_fkey" FOREIGN KEY ("classroom_id") REFERENCES "classrooms"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "classroom_activities" ADD CONSTRAINT "classroom_activities_created_by_user_id_fkey" FOREIGN KEY ("created_by_user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
