// This is not a real OAS type, but is used in multiple places, so it is abstracted
import { BaseOpenApiV3_1ConverterNode, } from "../../BaseOpenApiV3_1Converter.node";
import { XBearerFormatConverterNode } from "../extensions/auth/XBearerFormatConverter.node";
import { XFernHeaderAuthConverterNode } from "../extensions/auth/XFernHeaderAuthConverter.node";
import { XFernHeaderVariableNameConverterNode } from "../extensions/auth/XFernHeaderVariableNameConverter.node";
import { isApiKeySecurityScheme } from "../guards/isApiKeySecurityScheme";
export class HeaderSecuritySchemeConverterNode extends BaseOpenApiV3_1ConverterNode {
    headerName;
    // x-bearer-format
    headerBearerFormatNode;
    // x-fern-header
    headerAuthNode;
    // x-fern-header-variable-name
    headerVariableNameNode;
    constructor(args) {
        super(args);
        this.safeParse();
    }
    parse() {
        if (isApiKeySecurityScheme(this.input)) {
            this.headerName = this.input.name;
        }
        this.headerAuthNode = new XFernHeaderAuthConverterNode({
            input: this.input,
            context: this.context,
            accessPath: this.accessPath,
            pathId: this.pathId,
        });
        this.headerVariableNameNode = new XFernHeaderVariableNameConverterNode({
            input: this.input,
            context: this.context,
            accessPath: this.accessPath,
            pathId: this.pathId,
        });
        this.headerBearerFormatNode = new XBearerFormatConverterNode({
            input: this.input,
            context: this.context,
            accessPath: this.accessPath,
            pathId: this.pathId,
        });
    }
    convert() {
        const headerAuth = this.headerAuthNode?.convert();
        if (headerAuth == null) {
            return undefined;
        }
        return {
            type: "header",
            nameOverride: headerAuth?.name,
            headerWireValue: this.headerName ?? "Authorization",
            prefix: headerAuth?.prefix ?? this.headerBearerFormatNode?.convert(),
        };
    }
}
