import { isNonNullish } from "@fern-api/ui-core-utils";
import { BaseOpenApiV3_1ConverterNode, } from "../../BaseOpenApiV3_1Converter.node";
import { coalesceServers } from "../../utils/3.1/coalesceServers";
import { OperationObjectConverterNode } from "./OperationObjectConverter.node";
export class PathItemObjectConverterNode extends BaseOpenApiV3_1ConverterNode {
    servers;
    globalAuth;
    basePath;
    isWebhook;
    description;
    get;
    post;
    put;
    patch;
    delete;
    path;
    constructor(args, servers, globalAuth, basePath, isWebhook) {
        super(args);
        this.servers = servers;
        this.globalAuth = globalAuth;
        this.basePath = basePath;
        this.isWebhook = isWebhook;
        this.safeParse();
    }
    parse() {
        this.description = this.input.description;
        this.servers = coalesceServers(this.servers, this.input.servers, this.context, this.accessPath);
        const path = Array.isArray(this.pathId)
            ? this.pathId.join("/")
            : this.pathId;
        if (this.input.get != null) {
            this.get = new OperationObjectConverterNode({
                input: this.input.get,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "get",
            }, this.servers, this.globalAuth, path, "GET", this.basePath, this.isWebhook);
        }
        if (this.input.post != null) {
            this.post = new OperationObjectConverterNode({
                input: this.input.post,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "post",
            }, this.servers, this.globalAuth, path, "POST", this.basePath, this.isWebhook);
        }
        if (this.input.put != null) {
            this.put = new OperationObjectConverterNode({
                input: this.input.put,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "put",
            }, this.servers, this.globalAuth, path, "PUT", this.basePath);
        }
        if (this.input.patch != null) {
            this.patch = new OperationObjectConverterNode({
                input: this.input.patch,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "patch",
            }, this.servers, this.globalAuth, path, "PATCH", this.basePath);
        }
        if (this.input.delete != null) {
            this.delete = new OperationObjectConverterNode({
                input: this.input.delete,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "delete",
            }, this.servers, this.globalAuth, path, "DELETE", this.basePath);
        }
    }
    convert() {
        return [
            this.get?.convert(),
            this.post?.convert(),
            this.put?.convert(),
            this.patch?.convert(),
            this.delete?.convert(),
        ].filter(isNonNullish);
    }
}
