import { PluginFastifyInstance } from "types"
import mongoose from "mongoose"
const { Schema } = mongoose

export const MODEL_BASENAME = "workSession"

const workSessionSchema = new Schema(
  {
    _id: {
      type: String,
    },

    userId: {
      type: String,
      required: true,
    },

    accessType: {
      type: String,
      required: true,
      default: "anonymous",
      enum: ["anonymous"],
    },

    compositionId: {
      type: String,
      required: true,
    },

    project: {
      type: String,
      required: false,
    },

    expiryDate: {
      type: Date,
      required: true,
    },

    isActive: {
      type: Boolean,
      default: true,
    },

    permissions: {
      type: Number,
      default: 6, // read+write
    },

    pluginData: {
      type: Schema.Types.Mixed,
      default: {},
    },

    composition: {
      type: Schema.Types.Mixed,
      required: false,
    },
  },
  { timestamps: true },
)

export const createModels = (fastify: PluginFastifyInstance) => {
  return fastify.createModel(MODEL_BASENAME, workSessionSchema)
}
