import mongoose from 'mongoose';
import { AutoIncrementID } from '@typegoose/auto-increment';
import type { IFile, IFileMethods, FileModel } from '@/types/mongoose/file';

const FileSchema = new mongoose.Schema<IFile, FileModel, IFileMethods>({
	deleted: {
		type: Boolean,
		default: false
	},
	file_key: String,
	data_id: Number, // TODO - Wait until https://github.com/typegoose/auto-increment/pull/21 is merged and then change this to BigInt
	task_id: String,
	boss_app_id: String,
	supported_countries: [String],
	supported_languages: [String],
	password: String,
	attribute1: String,
	attribute2: String,
	attribute3: String,
	creator_pid: Number,
	name: String,
	type: String,
	hash: String,
	size: BigInt,
	notify_on_new: [String],
	notify_led: Boolean,
	created: BigInt,
	updated: BigInt
}, { id: false });

FileSchema.plugin(AutoIncrementID, {
	startAt: 50000, // * Start very high to avoid conflicts with Nintendo Data IDs
	field: 'data_id'
});

FileSchema.index({ task_id: 1, boss_app_id: 1 });
FileSchema.index({ task_id: 1, boss_app_id: 1, name: 1 });

export const File = mongoose.model<IFile, FileModel>('File', FileSchema);
