import "server-only";
import { asc, eq } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { courseResources, type CourseResource } from "@/lib/db/schema";

export async function listCourseResources(courseId: string): Promise<CourseResource[]> {
  return db
    .select()
    .from(courseResources)
    .where(eq(courseResources.courseId, courseId))
    .orderBy(asc(courseResources.position), asc(courseResources.createdAt));
}

export async function listLessonResources(lessonId: string): Promise<CourseResource[]> {
  return db
    .select()
    .from(courseResources)
    .where(eq(courseResources.lessonId, lessonId))
    .orderBy(asc(courseResources.position), asc(courseResources.createdAt));
}
