
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";

sourcemap.install();

connectWithRetry();
const sequenceEvaluatorRepositoryMongo = new SequenceEvaluatorRepositoryMongo();
const sequenceConstraintService = new SequenceEvaluationApplication(sequenceEvaluatorRepositoryMongo);

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();
