import { BaseOpenApiV3_1ConverterNode, } from "../../BaseOpenApiV3_1Converter.node";
import { convertToObjectProperties } from "../../utils/3.1/convertToObjectProperties";
import { resolveParameterReference } from "../../utils/3.1/resolveParameterReference";
import { extendType } from "../../utils/extendType";
import { ParameterBaseObjectConverterNode } from "../paths";
import { X_FERN_GLOBAL_HEADERS } from "./fernExtension.consts";
export class XFernGlobalHeadersConverterNode extends BaseOpenApiV3_1ConverterNode {
    globalHeaders;
    requiredProperties;
    constructor(args) {
        super(args);
        this.safeParse();
    }
    // This would be used to set a member on the node
    parse() {
        const headers = extendType(this.input)[X_FERN_GLOBAL_HEADERS]?.map((header) => {
            const { header: headerName, ...schema } = header;
            if ((schema.optional != null && !schema.optional) ||
                resolveParameterReference(schema, this.context.document)?.required) {
                this.requiredProperties ??= [];
                this.requiredProperties?.push(headerName);
            }
            return [
                headerName,
                new ParameterBaseObjectConverterNode({
                    input: schema,
                    context: this.context,
                    accessPath: this.accessPath,
                    pathId: this.pathId,
                }),
            ];
        });
        if (headers != null) {
            this.globalHeaders = Object.fromEntries(headers);
        }
    }
    convert() {
        return convertToObjectProperties(this.globalHeaders, this.requiredProperties)?.flat();
    }
}
