
import config from "./config";

import mongoose from "mongoose";
import sourcemap from "source-map-support";
import SequenceEvaluatorRepositoryMongo from "./_infra/SequenceEvaluatorRepositoryMongo";
import RESTServer from "./_ui/RESTServer";
import SequenceEvaluationApplication from "./application/SequenceEvaluationApplication";
import AntlrStepParser from "./_infra/AntlrStepParser";

sourcemap.install();

connectWithRetry();
const sequenceEvaluatorRepositoryMongo = new SequenceEvaluatorRepositoryMongo();
const stepParser = new AntlrStepParser()
const sequenceConstraintService = new SequenceEvaluationApplication(sequenceEvaluatorRepositoryMongo, stepParser);

function connectWithRetry(): Promise<void> {
    return mongoose.connect(config.database, { useUnifiedTopology: true, useNewUrlParser: true })
        .then(() => {
            // tslint:disable-next-line: no-console
            console.log("Connecting to database : " + config.database );
        });
}
// Create RESTServer
const httpServer = new RESTServer(config.port, sequenceConstraintService);

httpServer.start();
