const glob = require('glob');
const utils = require('./utils');
const Generator = require('./classes/Generator')

const SequelizeHandler = require('../resource-handlers/SequelizeHandler');

class Coderizer {

    async gen(templateDefinitionsPath, resourceHandler, resources, ignoredResources) {
        try {
            templateDefinitionsPath = utils.relateToExecPath(templateDefinitionsPath);
            const templateDefinitions = require(templateDefinitionsPath);
            resources = glob.sync(resources).map(r => utils.relateToExecPath(r));
            console.log('RESOURCE_HANDLER', resourceHandler);
            console.log('RESOURCES\n', resources);
            // TODO resource handler selection
            const classes = await (new SequelizeHandler()).handleResources(resources);
            Generator.generate(classes, templateDefinitionsPath, templateDefinitions);
        }
        catch(err) {
            console.error(err);
        }
    }
}

module.exports = Coderizer