import { eq } from "drizzle-orm";
import { db } from "../config/database.js";
import { exams, type Exam, type NewExam } from "./exams.schema.js";

export class ExamsRepository {
  async findById(id: string): Promise<Exam | undefined> {
    const [result] = await db
      .select()
      .from(exams)
      .where(eq(exams.id, id))
      .limit(1);
    return result;
  }

  async findByClassId(classId: string): Promise<Exam[]> {
    return db.select().from(exams).where(eq(exams.classId, classId));
  }

  async update(id: string, data: Partial<NewExam>): Promise<void> {
    await db.update(exams).set(data).where(eq(exams.id, id));
  }

  async delete(id: string): Promise<void> {
    await db.delete(exams).where(eq(exams.id, id));
  }
}

export const examsRepository = new ExamsRepository();
