import {
  getEssayCount,
  getEssays as dbGetEssays,
  getForum,
  ta,
} from "@/app/www/system/DB";
import { getLanguage } from "@/app/www/utilities/Utility";

export const getEssays = async (
  forumID: string,
  language: string,
  page: number,
) => {
  return ta(async (db) => {
    const forum = await getForum(db, forumID);
    if (forum) {
      return {
        title: getLanguage(language, forum),
        essayCount: Number(await getEssayCount(forumID)),
        essays: await dbGetEssays(forumID, page, 20),
        level: forum.level,
      };
    }
  });
};
