import { BriskRoute, Route, RouteGroup, RouteResource } from '@adonisjs/core/http';
import _ from 'lodash';
import { HandlerMetaData } from '../../lib/handler_metadata.js';
const _ROUTE_OPENAPI_OPTIONS_ = Symbol('Route openapi options');
Route.macro('openapi', function (options) {
    HandlerSetOptions(this.toJSON().handler, options);
    return this;
});
RouteResource.macro('openapi', function (options) {
    _.map(this.routes, (r) => r.openapi(options));
    return this;
});
RouteGroup.macro('openapi', function (options) {
    _.map(this.routes, (r) => (r instanceof BriskRoute ? r : r.openapi(options)));
    return this;
});
export const HandlerGetOptions = function (handler) {
    return HandlerMetaData.getMetaDataOfHandler(handler, _ROUTE_OPENAPI_OPTIONS_);
};
export const HandlerSetOptions = function (handler, options) {
    const previousOptions = HandlerMetaData.getMetaDataOfHandler(handler, _ROUTE_OPENAPI_OPTIONS_);
    const defaultOptions = {
        visible: true,
    };
    options = {
        ...previousOptions,
        ...(options || defaultOptions),
    };
    HandlerMetaData.setMetaDataOfHandler(handler, _ROUTE_OPENAPI_OPTIONS_, options);
};
export function OpenApiDescription(description) {
    return function (target, propertyName, descriptor) {
        const handler = { reference: [target.constructor, propertyName] };
        HandlerSetOptions(handler, { description });
        return descriptor;
    };
}
export function OpenApiName(name) {
    return function (target, propertyName, descriptor) {
        const handler = { reference: [target.constructor, propertyName] };
        HandlerSetOptions(handler, { name });
        return descriptor;
    };
}
//# sourceMappingURL=openapi_router_macros.js.map