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 {
    description;
    get;
    post;
    put;
    patch;
    delete;
    path;
    constructor(args) {
        super(args);
        this.safeParse(args);
    }
    parse({ servers, globalAuth, basePath, isWebhook }) {
        this.description = this.input.description;
        const coalescedServers = coalesceServers(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",
                servers: coalescedServers,
                globalAuth,
                path,
                method: "GET",
                basePath,
                isWebhook,
            });
        }
        if (this.input.post != null) {
            this.post = new OperationObjectConverterNode({
                input: this.input.post,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "post",
                servers: coalescedServers,
                globalAuth,
                path,
                method: "POST",
                basePath,
                isWebhook,
            });
        }
        if (this.input.put != null) {
            this.put = new OperationObjectConverterNode({
                input: this.input.put,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "put",
                servers: coalescedServers,
                globalAuth,
                path,
                method: "PUT",
                basePath,
                isWebhook: false,
            });
        }
        if (this.input.patch != null) {
            this.patch = new OperationObjectConverterNode({
                input: this.input.patch,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "patch",
                servers: coalescedServers,
                globalAuth,
                path,
                method: "PATCH",
                basePath,
                isWebhook: false,
            });
        }
        if (this.input.delete != null) {
            this.delete = new OperationObjectConverterNode({
                input: this.input.delete,
                context: this.context,
                accessPath: this.accessPath,
                pathId: "delete",
                servers: coalescedServers,
                globalAuth,
                path,
                method: "DELETE",
                basePath,
                isWebhook: false,
            });
        }
    }
    convert() {
        return [
            ...(this.get?.convert() ?? []),
            ...(this.post?.convert() ?? []),
            ...(this.put?.convert() ?? []),
            ...(this.patch?.convert() ?? []),
            ...(this.delete?.convert() ?? []),
        ].filter(isNonNullish);
    }
}
