import { IStory } from ".";
import { hasMigrated } from "~/lib/dbconfig";
import { IBand } from "~/models/band";
import { IFicmas } from "~/models/challenges/ficmas";
import { IChallenge } from "~/models/challenges/gen";
import { IUser } from "~/models/user";
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
import SequenceFactory from "mongoose-sequence";
import { Chapter } from "./chapter";

const AutoIncrement = SequenceFactory(mongoose);

export type IDraft = Omit<
	IStory,
	"recs" | "favs" | "reviews" | "views" | "downloads" | "posted"
>;

// const Cha

const DraftSchema = new Schema<IDraft>({
	title: {
		type: String,
	},
	_id: {
		type: Number,
	},
	coAuthor: {
		type: Number,
		ref: "User",
		default: null,
	},
	author: {
		type: Number,
		ref: "User",
	},
	chapters: [Chapter],
});

hasMigrated && DraftSchema.plugin(AutoIncrement, { id: "drafts" });

export const Draft: Model<IDraft> =
	/* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts");
