import { ConvertVideoWithFfmpegNodeInputModel, ConvertVideoWithFfmpegNodeOutputModel, ConvertVideoWithFfmpegNodeLocalInputModel, ConvertVideoWithFfmpegNodeClientInputModel, } from '../../../../../code/type/index.js';
import { buildCommandToConvertVideoWithFfmpeg } 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 convertVideoWithFfmpegNode(source) {
    const input = ConvertVideoWithFfmpegNodeInputModel.parse(source);
    switch (input.handle) {
        case 'remote':
            return await convertVideoWithFfmpegNodeRemote(input);
        case 'external':
            return await convertVideoWithFfmpegNodeLocalExternal(input);
        default:
            return await convertVideoWithFfmpegNodeLocalInternal(input);
    }
}
async function convertVideoWithFfmpegNodeLocalExternal(source) {
    const input = await resolveInputForConvertLocalExternalNode(source);
    return await convertVideoWithFfmpegNodeLocal(input);
}
async function convertVideoWithFfmpegNodeLocalInternal(source) {
    const input = await resolveInputForConvertLocalInternalNode(source);
    return await convertVideoWithFfmpegNodeLocal(input);
}
export async function convertVideoWithFfmpegNodeRemote(source) {
    const input = await resolveInputForConvertRemoteNode(source);
    const clientInput = ConvertVideoWithFfmpegNodeClientInputModel.parse(extend(input, { handle: 'client' }));
    const request = buildRequestToConvert(clientInput);
    await resolveWorkFileNode(request, input.output.file.path);
    return ConvertVideoWithFfmpegNodeOutputModel.parse({
        file: {
            path: input.output.file.path,
        },
    });
}
export async function convertVideoWithFfmpegNodeLocal(input) {
    const localInput = ConvertVideoWithFfmpegNodeLocalInputModel.parse(input);
    const sequence = await buildCommandToConvertVideoWithFfmpeg(localInput);
    await runCommandSequence(sequence);
    return ConvertVideoWithFfmpegNodeOutputModel.parse({
        file: {
            path: localInput.output.file.path,
        },
    });
}
//# sourceMappingURL=node.js.map