"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__tsfTypeAliases = exports.HttpLogPayloadMiddleware = exports.HttpMiddleware = void 0;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-reflection/type-metadata-runtime"));
const __tsf_metadata_type = _a.createCompactMetadataRegistryV1("[1,[{\"kind\":12,\"types\":[{\"kind\":3},{\"kind\":18,\"typeName\":\"HttpResponseResult\",\"types\":[]},{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":3},{\"kind\":18,\"typeName\":\"HttpResponseResult\",\"types\":[]}]}}],\"typeName\":\"HttpMiddlewareResult\"},{\"kind\":22,\"type\":{\"kind\":3}}]]", []);
let _HttpMiddlewareMetadata_1;
class HttpMiddleware {
    static __tsfType = _HttpMiddlewareMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpMiddleware\",\"typeName\":\"HttpMiddleware\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[{\"name\":\"handle\",\"parameters\":[{\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false,\"default\":false},{\"name\":\"response\",\"type\":{\"kind\":16,\"typeName\":\"HttpResponse\",\"classType\":{\"$tsfImport\":[1,\"./response\",\"HttpResponse\"]}},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":0}}],\"hasConstructor\":false,\"constructorParameters\":[]}]", [() => HttpMiddleware, require], __tsf_metadata_type);
}
exports.HttpMiddleware = HttpMiddleware;
_HttpMiddlewareMetadata_1.classType = HttpMiddleware;
HttpMiddleware.__tsfType = _HttpMiddlewareMetadata_1;
let _HttpLogPayloadMiddlewareMetadata_1;
class HttpLogPayloadMiddleware extends HttpMiddleware {
    logger;
    constructor(logger) {
        super();
        this.logger = logger;
    }
    async handle(request, _response) {
        this.logger.info('Logging request', {
            method: request.method,
            url: request.url,
            contentType: request.headers['content-type'] ?? '',
            body: await request.readBodyText()
        });
    }
    static __tsfType = _HttpLogPayloadMiddlewareMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpLogPayloadMiddleware\",\"typeName\":\"HttpLogPayloadMiddleware\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[{\"name\":\"handle\",\"parameters\":[{\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false,\"default\":false},{\"name\":\"_response\",\"type\":{\"kind\":16,\"typeName\":\"HttpResponse\",\"classType\":{\"$tsfImport\":[1,\"./response\",\"HttpResponse\"]}},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":1}}],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false,\"default\":false}]}]", [() => HttpLogPayloadMiddleware, require], __tsf_metadata_type);
}
exports.HttpLogPayloadMiddleware = HttpLogPayloadMiddleware;
_HttpLogPayloadMiddlewareMetadata_1.classType = HttpLogPayloadMiddleware;
HttpLogPayloadMiddleware.__tsfType = _HttpLogPayloadMiddlewareMetadata_1;
exports.__tsfTypeAliases = _a.decodeCompactMetadataV1("[1,{\"HttpMiddlewareFunction\":{\"kind\":2,\"typeName\":\"(request: HttpRequest, response: HttpResponse) =\\u003e HttpMiddlewareResult\",\"typeName\":\"HttpMiddlewareFunction\"},\"HttpMiddlewareInput\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"ClassType\",\"typeArguments\":[{\"kind\":16,\"typeName\":\"HttpMiddleware\",\"classType\":{\"$tsf\":0}}]},{\"kind\":2,\"typeName\":\"(request: HttpRequest, response: HttpResponse) =\\u003e HttpMiddlewareResult\",\"typeName\":\"HttpMiddlewareFunction\"}],\"typeName\":\"HttpMiddlewareInput\"},\"HttpMiddlewareResult\":{\"kind\":12,\"types\":[{\"kind\":3},{\"kind\":18,\"typeName\":\"HttpResponseResult\",\"types\":[]},{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":3},{\"kind\":18,\"typeName\":\"HttpResponseResult\",\"types\":[]}]}}],\"typeName\":\"HttpMiddlewareResult\"}}]", [() => (typeof HttpMiddleware !== "undefined" ? HttpMiddleware : (typeof exports !== "undefined" ? exports.HttpMiddleware : undefined))], __tsf_metadata_type);
//# sourceMappingURL=middleware.js.map