import mongoose from "mongoose";
import { Biffno } from "@models/challenges/biffno";
import { Ficmas } from "@models/challenges/ficmas";
import { Challenge } from "@models/challenges/gen";
import { log } from "./logger";

export default async function () {
	let beep = useRuntimeConfig();
	mongoose.set("overwriteModels", true);
	// console.log(process.env);
	try {
		log.debug("before ->", +mongoose.connection.modelNames().toString());
		await mongoose.connect(beep.database.uri, {
			auth: {
				username: beep.database.user,
				password: beep.database.password,
			},
			authSource: "admin",
		});
		// if (!!!mongoose.connections.length)
	} catch (e) {
		console.error(e);
		throw createError({
			statusCode: 500,
			message: "Could not connect to the database.",
		});
	}
}
