import { lt } from "drizzle-orm";
import { db } from "../../../database/dbclient.js";
import { prodlabels } from "../../../database/schema/prodLabels.js";
import { addDays } from "date-fns";
import { createLog } from "../../services/logger/logger.js";

export const deleteLabels = async () => {
    /**
     * Deletes labels older than 90 days from lst... all label data can be found in alpla prod.
     */
    try {
        await db
            .delete(prodlabels)
            .where(lt(prodlabels.upd_date, addDays(new Date(Date.now()), -90)));
    } catch (error) {
        createLog(
            "error",
            "labeling",
            "ocp",
            `Error deleting labels older than 90 days`
        );
    }
};
