"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Endpoint {
    constructor(method, url, controller) {
        this.method = method;
        this.url = url;
        this.controller = controller;
        this.middlewares = [];
        this.outputMiddlewares = [];
    }
    addMiddleware(middleware) {
        this.middlewares.push(middleware);
        return this;
    }
    addOutputMiddleware(middleware) {
        this.outputMiddlewares.push(middleware);
        return this;
    }
    apply(router) {
        const method = this.method, url = this.url;
        const middlewares = this.middlewares, controller = this.controller, outputMiddlewares = this.outputMiddlewares;
        // need a function to do nothing to stop the execution at the end
        // middlewares are circular so if they always keep calling next, it'll just keep looping
        const complete = () => { };
        const params = [
            url,
            ...middlewares,
            controller,
            ...outputMiddlewares,
            complete,
        ];
        // @ts-ignore
        router[method](...params);
    }
}
exports.default = Endpoint;
