import { getSettings } from "../../../util/settings.js";
import { getSchemaFromId } from "../util.js";
import { renderSchema } from "./schema.js";
export function renderOperation({ renderer, site, chunk, docsData, baseHeadingLevel, docsCodeSnippets, }) {
    renderer.appendHeading(baseHeadingLevel, `${chunk.chunkData.method.toUpperCase()} ${chunk.chunkData.path}`);
    if (chunk.chunkData.summary && chunk.chunkData.description) {
        renderer.appendText(`_${chunk.chunkData.summary}_`);
        renderer.appendText(chunk.chunkData.description);
    }
    else if (chunk.chunkData.summary) {
        renderer.appendText(chunk.chunkData.summary);
    }
    else if (chunk.chunkData.description) {
        renderer.appendText(chunk.chunkData.description);
    }
    if (chunk.chunkData.security || chunk.chunkData.globalSecurity) {
        renderer.appendHeading(baseHeadingLevel + 1, "Security");
        if (chunk.chunkData.security) {
            const securityChunk = getSchemaFromId(chunk.chunkData.security.contentChunkId, docsData);
            renderSchema({
                topLevelName: "Security",
                site,
                renderer,
                schema: securityChunk.chunkData.value,
                data: docsData,
                baseHeadingLevel: baseHeadingLevel + 2,
                labelStack: [],
            });
        }
        if (chunk.chunkData.globalSecurity) {
            const securityChunk = getSchemaFromId(chunk.chunkData.globalSecurity.contentChunkId, docsData);
            renderSchema({
                topLevelName: "Security",
                site,
                renderer,
                schema: securityChunk.chunkData.value,
                data: docsData,
                baseHeadingLevel: baseHeadingLevel + 2,
                labelStack: [],
            });
        }
    }
    if (chunk.chunkData.parameters.length > 0) {
        renderer.appendHeading(baseHeadingLevel + 1, "Parameters");
        for (const parameter of chunk.chunkData.parameters) {
            renderer.appendHeading(baseHeadingLevel + 2, `${parameter.name}${parameter.required ? " (required)" : ""}`);
            if (parameter.description) {
                renderer.appendText(parameter.description);
            }
            const parameterChunk = getSchemaFromId(parameter.fieldChunkId, docsData);
            renderSchema({
                topLevelName: "Security",
                site,
                renderer,
                schema: parameterChunk.chunkData.value,
                data: docsData,
                baseHeadingLevel: baseHeadingLevel + 2,
                labelStack: [],
            });
        }
    }
    const { tryItNow } = getSettings();
    const usageSnippet = docsCodeSnippets[chunk.id];
    if (usageSnippet && tryItNow) {
        renderer.appendHeading(baseHeadingLevel + 1, "Try it Now");
        // TODO: Zod is actually hard coded for now since its always a dependency
        // in our SDKs. Ideally this will come from the SDK package.
        renderer.appendTryItNow({
            externalDependencies: {
                zod: "^3.25.64",
                [tryItNow.npmPackageName]: "latest",
            },
            defaultValue: usageSnippet.code,
        });
    }
    if (chunk.chunkData.requestBody) {
        renderer.appendHeading(baseHeadingLevel + 1, `Request Body${chunk.chunkData.requestBody.required ? " (required)" : ""}`);
        if (chunk.chunkData.requestBody.description) {
            renderer.appendText(chunk.chunkData.requestBody.description);
        }
        const requestBodySchema = getSchemaFromId(chunk.chunkData.requestBody.contentChunkId, docsData);
        renderSchema({
            topLevelName: "Request Body",
            site,
            renderer,
            schema: requestBodySchema.chunkData.value,
            data: docsData,
            baseHeadingLevel: baseHeadingLevel + 2,
            labelStack: [],
        });
    }
    if (chunk.chunkData.responses) {
        for (const [statusCode, responses] of Object.entries(chunk.chunkData.responses)) {
            for (const response of responses) {
                renderer.appendHeading(baseHeadingLevel + 1, `Response: ${statusCode} (${response.contentType})`);
                if (response.description) {
                    renderer.appendText(response.description);
                }
                const responseSchema = getSchemaFromId(response.contentChunkId, docsData);
                renderSchema({
                    topLevelName: "Response Body",
                    site,
                    renderer,
                    schema: responseSchema.chunkData.value,
                    data: docsData,
                    baseHeadingLevel: baseHeadingLevel + 2,
                    labelStack: [],
                });
            }
        }
    }
}
//# sourceMappingURL=operation.js.map