ALTER TABLE "LessonWhiteboard" ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Admins have full access" ON "LessonWhiteboard" FOR ALL USING (is_admin());

CREATE POLICY "Users can view permitted lesson whiteboards" ON "LessonWhiteboard" FOR SELECT USING (
    is_admin() OR "lessonId" IN (SELECT auth_user_lessons())
);

CREATE POLICY "Teachers can update lesson whiteboards" ON "LessonWhiteboard" FOR UPDATE USING (
    is_admin() OR ("lessonId" IN (SELECT auth_user_lessons()) AND requesting_user_role() = 'teacher')
);

CREATE POLICY "Teachers can insert lesson whiteboards" ON "LessonWhiteboard" FOR INSERT WITH CHECK (
    is_admin() OR ("lessonId" IN (SELECT auth_user_lessons()) AND requesting_user_role() = 'teacher')
);
