-- CreateEnum
CREATE TYPE "Semester" AS ENUM ('GANJIL', 'GENAP');

-- CreateEnum
CREATE TYPE "Tingkat" AS ENUM ('X', 'XI', 'XII');

-- CreateEnum
CREATE TYPE "DimensiP3" AS ENUM ('BERIMAN_BERTAKWA', 'BERKEBINEKAAN_GLOBAL', 'BERGOTONG_ROYONG', 'MANDIRI', 'BERNALAR_KRITIS', 'KREATIF');

-- CreateTable
CREATE TABLE "cp_fase" (
    "id" TEXT NOT NULL,
    "tahunPelajaran" TEXT NOT NULL,
    "semester" "Semester" NOT NULL,
    "tingkat" "Tingkat" NOT NULL,
    "capaianPembelajaran" TEXT NOT NULL,
    "guruId" TEXT NOT NULL,
    "mapelId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "cp_fase_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "cp_element" (
    "id" TEXT NOT NULL,
    "elemen" TEXT NOT NULL,
    "capaianPembelajaran" TEXT NOT NULL,
    "cpFaseId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "cp_element_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "tujuan_pembelajaran" (
    "id" TEXT NOT NULL,
    "kode" TEXT NOT NULL,
    "kompetensi" TEXT NOT NULL,
    "lingkupMateri" TEXT NOT NULL,
    "cpElementId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "tujuan_pembelajaran_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "alur_tp" (
    "id" TEXT NOT NULL,
    "mingguKe" INTEGER NOT NULL,
    "alokasiWaktuJP" INTEGER NOT NULL,
    "profilPelajarPancasila" "DimensiP3"[],
    "tpId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "alur_tp_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "cp_fase_tahunPelajaran_semester_tingkat_guruId_mapelId_key" ON "cp_fase"("tahunPelajaran", "semester", "tingkat", "guruId", "mapelId");

-- AddForeignKey
ALTER TABLE "cp_fase" ADD CONSTRAINT "cp_fase_guruId_fkey" FOREIGN KEY ("guruId") REFERENCES "guru"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cp_fase" ADD CONSTRAINT "cp_fase_mapelId_fkey" FOREIGN KEY ("mapelId") REFERENCES "mapel"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cp_element" ADD CONSTRAINT "cp_element_cpFaseId_fkey" FOREIGN KEY ("cpFaseId") REFERENCES "cp_fase"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tujuan_pembelajaran" ADD CONSTRAINT "tujuan_pembelajaran_cpElementId_fkey" FOREIGN KEY ("cpElementId") REFERENCES "cp_element"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alur_tp" ADD CONSTRAINT "alur_tp_tpId_fkey" FOREIGN KEY ("tpId") REFERENCES "tujuan_pembelajaran"("id") ON DELETE CASCADE ON UPDATE CASCADE;
