import { model, Schema } from 'mongoose';
const cronUpdateDatesSchema = new Schema({
    key: { type: String, required: true, unique: true },
    date: { type: Date, required: true },
});
cronUpdateDatesSchema.index({ key: 1 });
export const CronUpdateDatesModel = model('CronUpdateDates', cronUpdateDatesSchema);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const createHandler = (keyCreator) => [
    (...x) => CronUpdateDatesModel.findOne({ key: keyCreator(...x) })
        .lean()
        .then(x => x === null || x === void 0 ? void 0 : x.date),
    (...x) => CronUpdateDatesModel.updateOne({ key: keyCreator(...x) }, { $set: { date: new Date() } }, { upsert: true })
        .lean()
        // eslint-disable-next-line @typescript-eslint/no-empty-function
        .then(() => { }),
];
export const [getWorkItemUpdateDate, setWorkItemUpdateDate] = createHandler((collection) => `${collection}:work-items`);
export const [getLastBuildUpdateDate, setLastBuildUpdateDate] = createHandler((collection, project) => `${collection}:${project}:builds`);
export const [getLastReleaseFetchDate, setLastReleaseFetchDate] = createHandler((collection, project) => `${collection}:${project}:releases`);
export const [getLastTestRunDate, setLastTestRunDate] = createHandler((collection, project) => `${collection}:${project}:test-runs`);
