const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
const require_models_dictionary_model = require('../../models/dictionary.model.cjs');
const require_logger_index = require('../../logger/index.cjs');
const require_models_organization_model = require('../../models/organization.model.cjs');
const require_models_project_model = require('../../models/project.model.cjs');
const require_models_tag_model = require('../../models/tag.model.cjs');
const require_models_user_model = require('../../models/user.model.cjs');
const require_models_oAuth2_model = require('../../models/oAuth2.model.cjs');
let mongoose = require("mongoose");
mongoose = require_rolldown_runtime.__toESM(mongoose);

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

//#endregion
exports.connectDB = connectDB;
//# sourceMappingURL=connectDB.cjs.map