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

export const MODEL_BASENAME = "project"

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

    title: {
      type: String,
      required: true,
      maxLength: 200,
    },

    account: {
      type: Schema.Types.String,
      ref: "raclette__core-account",
      default: null,
    },

    tags: {
      type: [Schema.Types.String],
      ref: "raclette__core-tag",
      default: [],
    },

    description: { type: String },

    isDefault: { type: Boolean, default: false },

    // soft delete
    isDeleted: { type: Boolean, default: false },
    config: {
      type: {
        tags: {
          type: [Schema.Types.String],
          ref: "raclette__core-tag",
          default: [],
        },
        railPageNavigation: {
          type: Boolean,
          default: false,
        },
      },
      default: () => ({
        tags: [],
        railPageNavigation: false,
      }),
    },
  },
  { timestamps: true },
)

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