"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
let base = require('../index'); // replace with let base = require('node-base-module');
/**
 * For more detailde exemple check templates/express.ts
 */
class SimpleWebServer {
    constructor() {
        /**
         * Default initialization can be found in node-base-module/options.json
         * To set your custom setting can use base.setDefaultOptions or base.resetDefaultOptions
         * Both functions will replace global the default settings
         * If some settings is missing from new setting module will keep the old one
         * Express use from setting just next groups:
         *      "swagger" - to configurate the swagger if swagger/isActive are true else swagger will not be integrated
         *      "morgan" - to specify if morgan is integrated or not
         *      "logStream" - to configurate the acces log
         */
        base.setDefaultOptions({
            "swagger": {
                "swaggerDefinition": {
                    "info": {
                        "title": "Simple Web Server",
                        "version": "1.0.0",
                        "description": "Demo for node-base-module"
                    },
                    "basePath": "/"
                },
                "apis": ["./lib/demo/simpleWebServer.js"],
            }
        });
        base.logger().setLogLevel(base.LOG_LEVEL.INFO);
        /**
         * Get your own express web server
         * You can use base.express()
         * Here you can alse specifay custom setting without affecting global setting
         * Any setting specifay to this function will afect just that express instance
         */
        var express = base.express();
        /**
         * Generate an express client
         * To get access to express client use express.initialize()
         * At this point if you skip "Step 3." will be generated a default "log stream"
         * else will be youse your own "log stream"
         * Same for setting, if you set options.morgan.isActive to false, will not be integrate morgane
         * to your express client. Same for this.options.swagger.isActive.
         */
        this.app = express.initialize();
        base.crashreporter();
        /**
         * Include routes (with swagger documentation)
         * To include your own route use express client generated at "Step 5" with function express.initialize()
         */
        /**
         * @swagger
         * /test:
         *   get:
         *     summary: Get
         *     description:
         *       "Make test request"
         *     tags:
         *       - Comands
         *     produces:
         *         - "application/json"
         *     responses:
         *       200:
         *         description: OK
         */
        this.app.get('/test', function (req, res, next) {
            return base.Static.sendResponse(res, 200, "Our test response", {});
        });
        /**
          * @swagger
          * /test:
          *   get:
          *     summary: Get
          *     description:
          *       "Make test request"
          *     tags:
          *       - Comands
          *     produces:
          *         - "application/json"
          *     responses:
          *       200:
          *         description: OK
          *       500:
          *         description: Error
          */
        this.app.get('/test_promisefy', function (req, res) {
            return __awaiter(this, void 0, void 0, function* () {
                function test(arg1, callback) {
                    console.log(arg1);
                    console.log(callback);
                    //throw new Error('error');
                    //callback(false, new Error('error'));
                    callback(true, arg1);
                }
                ;
                // let controller = function(succes:boolean, data:any){
                //     if (succes) {
                //         if(options.resolve!= undefined)
                //             options.resolve(data);
                //     }
                //     else {
                //         if(options.reject != undefined)
                //             options.reject(data);
                //     }
                // }
                // let redis = base.redis();
                let options = {
                    args: ["*"],
                };
                let { success, data } = yield base.Static.promisefy(test, options);
                // let {success, data} = await base.Static.promisefy(redis.keys, options);     
                if (success)
                    return base.Static.sendResponse(res, 200, data);
                else
                    return base.Static.sendResponse(res, 500, data.message);
            });
        });
        /**
         * Also you can check auto generated routes:
         *      "/health" for functionality
         *      "/swagger.json" for swagger documentation
         */
        /**
         * Public your webserver
         */
        let port = 9876;
        this.server = this.app.listen(port);
    }
}
new SimpleWebServer();
//# sourceMappingURL=simpleWebServer.js.map