-- CreateEnum
CREATE TYPE "UserRole" AS ENUM ('ADMIN', 'TEACHER', 'STUDENT');

-- CreateEnum
CREATE TYPE "SchoolClubRole" AS ENUM ('PRESIDENT', 'VICE_PRESIDENT', 'MEMBER');

-- CreateEnum
CREATE TYPE "SchoolEventVisibility" AS ENUM ('PUBLIC', 'CLASS_ONLY', 'CLUB_ONLY');

-- CreateTable
CREATE TABLE "SchoolEvent" (
    "id" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "date" TIMESTAMP(3) NOT NULL,
    "time" TEXT,
    "location" TEXT,
    "visibility" "SchoolEventVisibility" NOT NULL,
    "createdBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "SchoolEventAttendance" (
    "id" TEXT NOT NULL,
    "eventId" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "role" "UserRole" NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "SchoolClub" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "SchoolClubMember" (
    "id" TEXT NOT NULL,
    "clubId" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "role" "SchoolClubRole" NOT NULL,

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

-- CreateTable
CREATE TABLE "SchoolClubEvent" (
    "id" TEXT NOT NULL,
    "clubId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "date" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- AddForeignKey
ALTER TABLE "SchoolEventAttendance" ADD CONSTRAINT "SchoolEventAttendance_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "SchoolEvent"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SchoolClubMember" ADD CONSTRAINT "SchoolClubMember_clubId_fkey" FOREIGN KEY ("clubId") REFERENCES "SchoolClub"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SchoolClubEvent" ADD CONSTRAINT "SchoolClubEvent_clubId_fkey" FOREIGN KEY ("clubId") REFERENCES "SchoolClub"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
