import { DictionaryModel } from "../../models/dictionary.model.mjs";
import { logger } from "../../logger/index.mjs";
import { OrganizationModel } from "../../models/organization.model.mjs";
import { ProjectModel } from "../../models/project.model.mjs";
import { TagModel } from "../../models/tag.model.mjs";
import { UserModel } from "../../models/user.model.mjs";
import { OAuth2AccessTokenModel } from "../../models/oAuth2.model.mjs";
import { connect } from "mongoose";

//#region src/utils/mongoDB/connectDB.ts
const connectDB = async () => {
	try {
		const client = await connect(`mongodb+srv://${process.env.DB_ID}:${process.env.DB_MDP}@${process.env.DB_CLUSTER}/?retryWrites=true&w=majority&appName=Cluster0`);
		logger.info("MongoDB connected");
		await ProjectModel.syncIndexes();
		await UserModel.createIndexes();
		await OAuth2AccessTokenModel.createIndexes();
		await TagModel.createIndexes();
		await DictionaryModel.createIndexes();
		await OrganizationModel.createIndexes();
		return client.connection.getClient();
	} catch (error) {
		const errorMessage = `MongoDB connection error - ${error.message}`;
		logger.error(errorMessage);
		throw new Error(errorMessage);
	}
};

//#endregion
export { connectDB };
//# sourceMappingURL=connectDB.mjs.map