import { FernRegistry } from "../../../client/generated";
import { BaseOpenApiV3_1ConverterNode, } from "../../BaseOpenApiV3_1Converter.node";
import { XFernServerNameConverterNode } from "../extensions/XFernServerNameConverter.node";
export class ServerObjectConverterNode extends BaseOpenApiV3_1ConverterNode {
    url;
    serverName;
    constructor(args) {
        super(args);
        this.safeParse();
    }
    parse() {
        this.url =
            Object.entries(this.input.variables ?? {}).reduce((url, [key, value]) => {
                return url.replace(`{${key}}`, value.default);
            }, this.input.url) ?? this.input.url;
        this.serverName = new XFernServerNameConverterNode({
            input: this.input,
            context: this.context,
            accessPath: this.accessPath,
            pathId: this.pathId,
        });
    }
    convert() {
        const serverName = this.serverName?.convert() ?? this.url;
        if (this.url == null || serverName == null) {
            return undefined;
        }
        return {
            id: FernRegistry.EnvironmentId(serverName),
            baseUrl: this.url,
        };
    }
}
