import { MongoClient, Collection } from 'mongodb';

// You can define any db name you are looking for here
export const DB_NAME = 'anamnesis';
const DATABASE_URL = 'mongodb://localhost:27017/' + DB_NAME;

let databaseClient: MongoClient;


export function connectToDatabaseServer() {

    return new Promise<void>((resolve, reject) => {
        const defaultMongoClient = new MongoClient(DATABASE_URL);
    
        defaultMongoClient.connect(async (error, returnedDatabaseClient) => {
            if (error) {
                reject(error);
                return;
            }

            databaseClient = returnedDatabaseClient;
            resolve();
        });
    })
}

export function getDatabaseClient() {
    return databaseClient;
}