var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { createReadStream } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { controller, Status, Res } from '@ditsmod/core';
import { webpackDist } from './swagger-ui/constants.js';
import { oasRoute } from './decorators/oas-route.js';
import { OasConfigFiles } from './types/oas-extension-options.js';
let OpenapiController = class OpenapiController {
    res;
    constructor(res) {
        this.res = res;
    }
    async getIndex() {
        const indexHtml = await readFile(`${webpackDist}/index.html`, 'utf8');
        this.res.setContentType('text/html; charset=utf-8').send(indexHtml);
    }
    async getYaml(configFiles) {
        this.res.setContentType('text/yaml; charset=utf-8').send(configFiles.yaml);
    }
    async getJson(configFiles) {
        this.res.setContentType('application/json; charset=utf-8').send(configFiles.json);
    }
    getJavaScript() {
        this.res.setContentType('text/javascript; charset=utf-8');
        return new Promise((resolve, reject) => {
            createReadStream(`${webpackDist}/openapi.bundle.js`)
                .on('close', resolve)
                .on('error', reject)
                .pipe(this.res.rawRes);
        });
    }
};
__decorate([
    oasRoute('GET', 'openapi', {
        description: 'OpenAPI documentation',
        parameters: [],
        responses: {
            [Status.OK]: {
                description: 'Index file for the OpenAPI Specification',
                content: { ['text/html; charset=utf-8']: {} },
            },
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], OpenapiController.prototype, "getIndex", null);
__decorate([
    oasRoute('GET', 'openapi.yaml', {
        description: 'Config file in YAML format for the OpenAPI documentation',
        parameters: [],
        responses: {
            [Status.OK]: {
                description: 'YAML-file for the OpenAPI documentation',
                content: { ['text/yaml; charset=utf-8']: {} },
            },
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [OasConfigFiles]),
    __metadata("design:returntype", Promise)
], OpenapiController.prototype, "getYaml", null);
__decorate([
    oasRoute('GET', 'openapi.json', {
        description: 'Config file in JSON format for the OpenAPI documentation',
        parameters: [],
        responses: {
            [Status.OK]: {
                description: 'JSON-file for the OpenAPI documentation',
                content: { ['application/json; charset=utf-8']: {} },
            },
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [OasConfigFiles]),
    __metadata("design:returntype", Promise)
], OpenapiController.prototype, "getJson", null);
__decorate([
    oasRoute('GET', 'openapi.bundle.js', {
        description: 'SwaggerUI JavaScript bundle',
        parameters: [],
        responses: {
            [Status.OK]: {
                description: 'JavaScript-file with SwaggerUI logic',
                content: { ['text/javascript; charset=utf-8']: {} },
            },
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], OpenapiController.prototype, "getJavaScript", null);
OpenapiController = __decorate([
    controller(),
    __metadata("design:paramtypes", [Res])
], OpenapiController);
export { OpenapiController };
//# sourceMappingURL=openapi.controller.js.map