// src/models/ide-session.ts
// Copyright (C) 2026 Robert Colbert <rob.colbert@openplatform.us>
// All Rights Reserved

import { Schema, model } from "mongoose";
import { nanoid } from "nanoid";

import { IIdeSession } from "@gadget/api";

const IdeSessionSchema = new Schema<IIdeSession>({
  _id: { type: String, default: () => nanoid() },
  createdAt: { type: Date, default: Date.now, required: true },
  user: { type: String, required: true, ref: "User" },
});

IdeSessionSchema.index({
  user: 1,
  createdAt: -1,
});

export const IdeSession = model<IIdeSession>("IdeSession", IdeSessionSchema);
export default IdeSession;

(async () => {
  await IdeSession.syncIndexes();
})();
