import { eq, sql } from "drizzle-orm";
import { db } from "../../../../database/dbclient.js";
import { logs } from "../../../../database/schema/logs.js";
import { createLog } from "../logger.js";

export const clearLog = async (id: string) => {
    /**
     * mark the log as cleared
     */

    try {
        const clear = await db
            .update(logs)
            .set({ checked: true, created_at: sql`NOW()` })
            .where(eq(logs.log_id, id));
        createLog("info", "lst", "logger", "Log just cleared.");
        return { success: true, message: "Log was just cleared." };
    } catch (error) {
        createLog(
            "error",
            "lst",
            "logger",
            "There was an error clearing the log."
        );
        return {
            success: false,
            message: "There was an error clearing the log.",
        };
    }
};
