import { model, Schema } from 'mongoose';
const projectSchema = new Schema({
    id: { type: String, required: true },
    name: { type: String, required: true },
    description: { type: String },
    url: { type: String },
    state: { type: String, required: true },
    revision: { type: Number },
    visibility: { type: String },
    lastUpdatedTime: { type: Date },
});
projectSchema.index({ collectionName: 1, name: 1 });
const ProjectModel = model('Project', projectSchema);
export const bulkSaveProjects = (collectionName) => (projects) => ProjectModel.bulkWrite(projects.map(project => {
    const { id, ...rest } = project;
    return {
        updateOne: {
            filter: {
                collectionName,
                id,
            },
            update: { $set: { ...rest } },
            upsert: true,
        },
    };
}));
export const getProjects = (collectionName) => ProjectModel.find({ collectionName }).lean();
