import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http';
import internalWorklist from '../collections/internalworklist';
let collections = {};

if (Meteor.isServer) {

    const result = HTTP.call('GET', `${Meteor.settings.worklistUrl}/HISIntegration.svc/rest/GetHISBrandsRest`);
    let brandsHttpResult = JSON.parse(result.content);


    let collectionNames = brandsHttpResult.Items.map(brandObj => {
        return brandObj.Name
    })

    // let collectionNames = ["TestWLS"];

    for (let collName of collectionNames) {
        if (collName != "InternalHis")
            collections[collName] = new Mongo.Collection(collName);
        else
            collections[collName] = internalWorklist;
    }

}

if (Meteor.isClient || Meteor.isCordova) {
    // Meteor.call("getBrandsName", function(err, result) {
    //     let collectionNames = result;
    //     // let collectionNames = ["TestWLS"];

    //     for (let collName of collectionNames) {
    //         if (collName != "InternalHis")
    //             collections[collName] = new Mongo.Collection(collName);
    //         else
    //             collections[collName] = internalWorklist;
    //     }
    // });
    collections["InternalHis"] = internalWorklist;
}

export default collections;