/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import * as Python from './Python.js';
/**
 * Facade to interact with kernels by requesting code execution.
 */
export class RuntimeSnippetsFacade {
    static $language = new Map();
    /**
     * Register a facade for a given language
     *
     * @param language Kernel language
     * @param API Kernel API
     */
    static register(language, API) {
        this.$language.set(language, API);
    }
    /**
     * Whether there is an API for the given kernel language
     *
     * @param language Kernel language
     */
    static supports(language) {
        return this.$language.has(language);
    }
    _language;
    /**
     * Create a kernel snippet generator for a given kernel language.
     *
     * @param language Kernel language
     */
    constructor(language) {
        if (!RuntimeSnippetsFacade.$language.has(language)) {
            throw new Error(`${language} is not supported.`);
        }
        this._language = language;
    }
    /**
     * Kernel language
     */
    get language() {
        return this._language;
    }
    /**
     * Code snippet to change the current working directory.
     *
     * The code snippet has no returned value.
     *
     * @param path New current directory
     * @returns The code snippet
     */
    changeCurrentWorkingDirectory(path) {
        return RuntimeSnippetsFacade.$language
            .get(this.language)
            .changeCurrentWorkingDirectory(path);
    }
    /**
     * Code snippet to list the transferable kernel variables.
     *
     * @returns The code snippet
     */
    listVariables() {
        return RuntimeSnippetsFacade.$language.get(this.language).listVariables();
    }
    /**
     * Code snippet to load kernel variables.
     *
     * @param variables Serialized-JSON dictionary (<variable name>, <variable value blob>)
     * @returns The code snippet
     */
    loadVariables(variables) {
        return RuntimeSnippetsFacade.$language
            .get(this.language)
            .loadVariables(variables);
    }
    /**
     * Code snippet to save kernel variables.
     *
     * @param variables Variable names.
     * @returns The code snippet
     */
    saveVariables(variables) {
        return RuntimeSnippetsFacade.$language
            .get(this.language)
            .saveVariables(variables);
    }
    /**
     * Extract output variables candidates by parsing the cell content.
     *
     * @param code Cell code source
     * @returns The output variable candidates
     */
    getOutputCandidates(code) {
        return RuntimeSnippetsFacade.$language
            .get(this.language)
            .getOutputCandidates(code);
    }
}
RuntimeSnippetsFacade.register('python', Python);
