import { FernRegistry } from "../../../../client/generated";
import { BaseOpenApiV3_1ConverterNode, } from "../../../BaseOpenApiV3_1Converter.node";
import { extendType } from "../../../utils/extendType";
import { REDOC_CODE_SAMPLES_CAMEL, REDOC_CODE_SAMPLES_KEBAB, } from "../openApiExtension.consts";
export class RedocExampleConverterNode extends BaseOpenApiV3_1ConverterNode {
    codeSamples;
    constructor(args) {
        super(args);
        this.safeParse();
    }
    // This would be used to set a member on the node
    parse() {
        this.codeSamples = [
            ...(extendType(this.input)[REDOC_CODE_SAMPLES_KEBAB] ?? []),
            ...(extendType(this.input)[REDOC_CODE_SAMPLES_CAMEL] ?? []),
        ];
        this.codeSamples.forEach((codeSample) => {
            if (![
                ...Object.values(FernRegistry.api.v1.read.SupportedLanguage),
                "Kotlin",
                "Swift",
                "PHP",
            ]
                .map((l) => l.toLowerCase())
                .includes(codeSample.lang.toLowerCase())) {
                this.context.errors.warning({
                    message: `Unsupported language: ${codeSample.lang}. This may not render correctly.`,
                    path: this.accessPath,
                });
            }
        });
    }
    convert() {
        const convertedCodeSamples = {};
        this.codeSamples?.forEach((codeSample) => {
            convertedCodeSamples[codeSample.lang.toLowerCase()] ??= [];
            convertedCodeSamples[codeSample.lang.toLowerCase()]?.push({
                name: codeSample.label,
                language: codeSample.lang,
                code: codeSample.source,
                install: undefined,
                generated: false,
                description: undefined,
            });
        });
        if (Object.keys(convertedCodeSamples).length === 0) {
            return undefined;
        }
        return convertedCodeSamples;
    }
}
