"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleFileSystemRequests = handleFileSystemRequests;
const fileSystemCommands_1 = require("./fileSystemCommands");
function handleFileSystemRequests(onCommand, dispatch, frontApplet) {
    onCommand(async (commandEvent) => {
        switch (commandEvent.command.type) {
            case fileSystemCommands_1.FileSystemListOfStorageUnitsRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemListOfStorageUnitsResult,
                    storageUnits: await frontApplet.fileSystem.listStorageUnits(),
                });
                break;
            case fileSystemCommands_1.FileSystemListOfInternalStorageUnitsRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemListOfInternalStorageUnitsResult,
                    storageUnits: await frontApplet.fileSystem.listInternalStorageUnits(),
                });
                break;
            case fileSystemCommands_1.FileSystemListFilesRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemListFilesResult,
                    pathList: await frontApplet.fileSystem.listFiles(commandEvent.command.filePath),
                });
                break;
            case fileSystemCommands_1.FileSystemGetFileRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemGetFileResult,
                    file: await frontApplet.fileSystem.getFile(commandEvent.command.filePath),
                });
                break;
            case fileSystemCommands_1.FileSystemExistsRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemExistsResult,
                    result: await frontApplet.fileSystem.exists(commandEvent.command.filePath),
                });
                break;
            case fileSystemCommands_1.FileSystemDownloadFileRequest:
                await frontApplet.fileSystem.downloadFile(commandEvent.command.filePath, commandEvent.command.sourceUri, commandEvent.command.headers);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemDownloadFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemDeleteFileRequest:
                await frontApplet.fileSystem.deleteFile(commandEvent.command.filePath, commandEvent.command.recursive);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemDeleteFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemMoveFileRequest:
                await frontApplet.fileSystem.moveFile(commandEvent.command.sourceFilePath, commandEvent.command.destinationFilePath, commandEvent.command.options);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemMoveFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemGetFileChecksumRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemGetFileChecksumResult,
                    result: await frontApplet.fileSystem.getFileChecksum(commandEvent.command.filePath, commandEvent.command.hashType),
                });
                break;
            case fileSystemCommands_1.FileSystemExtractFileRequest:
                await frontApplet.fileSystem.extractFile(commandEvent.command.archiveFilePath, commandEvent.command.destinationDirectionPath, commandEvent.command.method);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemExtractFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemCreateDirectoryRequest:
                await frontApplet.fileSystem.createDirectory(commandEvent.command.directoryPath);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemCreateDirectoryResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemCreateArchiveFileRequest:
                await frontApplet.fileSystem.createArchive(commandEvent.command.archiveFilePath, commandEvent.command.archiveEntries);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemCreateArchiveFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemIsDirectoryRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemIsDirectoryResult,
                    result: await frontApplet.fileSystem.isDirectory(commandEvent.command.filePath),
                });
                break;
            case fileSystemCommands_1.FileSystemCopyFileRequest:
                await frontApplet.fileSystem.copyFile(commandEvent.command.sourceFilePath, commandEvent.command.destinationFilePath, commandEvent.command.options);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemCopyFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemWriteFileRequest:
                await frontApplet.fileSystem.writeFile(commandEvent.command.filePath, commandEvent.command.content);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemWriteFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemAppendFileRequest:
                await frontApplet.fileSystem.appendFile(commandEvent.command.filePath, commandEvent.command.content);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemAppendFileResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemReadFileRequest:
                await dispatch({
                    type: fileSystemCommands_1.FileSystemReadFileResult,
                    data: await frontApplet.fileSystem.readFile(commandEvent.command.filePath),
                });
                break;
            case fileSystemCommands_1.FileSystemWipeoutRequest:
                await frontApplet.fileSystem.wipeout();
                await dispatch({
                    type: fileSystemCommands_1.FileSystemWipeoutResult,
                    result: {},
                });
                break;
            case fileSystemCommands_1.FileSystemLinkRequest:
                await frontApplet.fileSystem.link(commandEvent.command.sourceFilePath, commandEvent.command.destinationFilePath);
                await dispatch({
                    type: fileSystemCommands_1.FileSystemLinkResult,
                    result: {},
                });
                break;
            default:
        }
    });
}
//# sourceMappingURL=handleFileSystemRequests.js.map