import { ConvertDocumentWithJupyterNodeInputModel, ConvertDocumentWithJupyterNodeOutputModel, ConvertDocumentWithJupyterNodeLocalInputModel, ConvertDocumentWithJupyterNodeClientInputModel, } from '../../../../../code/type/index.js';
import { buildCommandToConvertDocumentWithJupyter } from '../command.js';
import { runCommandSequence } from '../../../../../code/tool/node/command.js';
import { resolveInputForConvertLocalExternalNode, resolveInputForConvertLocalInternalNode, resolveInputForConvertRemoteNode, } from '../../tool/node.js';
import { extend } from '../../../../../code/tool/shared/object.js';
import { buildRequestToConvert, } from '../../shared.js';
import { resolveWorkFileNode } from '../../../../../code/tool/node/request.js';
export async function convertDocumentWithJupyterNode(source) {
    const input = ConvertDocumentWithJupyterNodeInputModel.parse(source);
    switch (input.handle) {
        case 'remote':
            return await convertDocumentWithJupyterNodeRemote(input);
        case 'external':
            return await convertDocumentWithJupyterNodeLocalExternal(input);
        default:
            return await convertDocumentWithJupyterNodeLocalInternal(input);
    }
}
async function convertDocumentWithJupyterNodeLocalExternal(source) {
    const input = await resolveInputForConvertLocalExternalNode(source);
    return await convertDocumentWithJupyterNodeLocal(input);
}
async function convertDocumentWithJupyterNodeLocalInternal(source) {
    const input = await resolveInputForConvertLocalInternalNode(source);
    return await convertDocumentWithJupyterNodeLocal(input);
}
export async function convertDocumentWithJupyterNodeRemote(source) {
    const input = await resolveInputForConvertRemoteNode(source);
    const clientInput = ConvertDocumentWithJupyterNodeClientInputModel.parse(extend(input, { handle: 'client' }));
    const request = buildRequestToConvert(clientInput);
    await resolveWorkFileNode(request, input.output.file.path);
    return ConvertDocumentWithJupyterNodeOutputModel.parse({
        file: {
            path: input.output.file.path,
        },
    });
}
export async function convertDocumentWithJupyterNodeLocal(input) {
    const localInput = ConvertDocumentWithJupyterNodeLocalInputModel.parse(input);
    const sequence = await buildCommandToConvertDocumentWithJupyter(localInput);
    await runCommandSequence(sequence);
    return ConvertDocumentWithJupyterNodeOutputModel.parse({
        file: {
            path: localInput.output.file.path,
        },
    });
}
//# sourceMappingURL=node.js.map