
const findService = require('./FindService');

const initOptions = (options) => {
    options = options ? options : {};
    const systemTypeComponent = 'systemTypeComponent';
    if (config.get("dataServices")[systemTypeComponent]) {   
        options.connectionName = systemTypeComponent;
    }

    return options;
}; 


module.exports = {

    getComponent: (field, userId, options) => {
        options = initOptions(options);
        const query = DBProvider.componentService.getComponentQuery(field,options);
        return findService.findAll(query, userId, null, null, options);
    },

    getComponentLibraryDocuments: (field, userId, options) => {
        options = initOptions(options);
        const query = DBProvider.componentService.getComponentLibrariesQuery(field, options);
        return findService.findAll(query, userId, null, null, options);
    },

    getListComponentResources: (userId, options) => {
        options = initOptions(options);
        const query = DBProvider.componentService.getListComponentResourcesQuery(options);
        return findService.findAll(query, userId, null, null, options);
    },

    getVendorLibrary: (name, userId, options) => {
        options = initOptions(options);
        const query = DBProvider.componentService.getVendorLibraryQuery(name, options);
        return findService.findAll(query, userId, null, null, options);
    },

    getVendorLibraries: (userId, options) => {
        options = initOptions(options);
        const query = DBProvider.componentService.getVendorLibrariesQuery(options);
        return findService.findAll(query, userId, null, null, options);
    }

};