"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleOfflineCacheRequests = handleOfflineCacheRequests;
const offlineCacheCommands_1 = require("./offlineCacheCommands");
function handleOfflineCacheRequests(onCommand, dispatch, frontApplet) {
    onCommand(async (commandEvent) => {
        switch (commandEvent.command.type) {
            case offlineCacheCommands_1.OfflineCacheListFiles:
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheFilesListed,
                    fileUids: await frontApplet.offline.cache.listFiles(),
                });
                break;
            case offlineCacheCommands_1.OfflineCacheLoadFile:
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheFileLoaded,
                    file: await frontApplet.offline.cache.loadFile(commandEvent.command.uid),
                });
                break;
            case offlineCacheCommands_1.OfflineCacheGetChecksumRequest:
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheGetChecksumResult,
                    result: await frontApplet.offline.cache.getChecksumFile(commandEvent.command.uid, commandEvent.command.hashType),
                });
                break;
            case offlineCacheCommands_1.OfflineCacheValidateChecksumRequest:
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheValidateChecksumResult,
                    result: await frontApplet.offline.cache.validateChecksumFile(commandEvent.command.uid, commandEvent.command.hash, commandEvent.command.hashType),
                });
                break;
            case offlineCacheCommands_1.OfflineCacheLoadOrSaveFileRequest:
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheLoadOrSaveFileResult,
                    file: await frontApplet.offline.cache.loadOrSaveFile(commandEvent.command.uid, commandEvent.command.uri, commandEvent.command.headers),
                });
                break;
            case offlineCacheCommands_1.OfflineCacheDeleteFileRequest:
                await frontApplet.offline.cache.deleteFile(commandEvent.command.uid);
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheDeleteFileResult,
                    result: {},
                });
                break;
            case offlineCacheCommands_1.OfflineCacheListContentRequest:
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheListContentResult,
                    result: await frontApplet.offline.cache.listContents(),
                });
                break;
            case offlineCacheCommands_1.OfflineCacheLoadContentRequest:
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheLoadContentResult,
                    result: await frontApplet.offline.cache.loadContent(commandEvent.command.uid),
                });
                break;
            case offlineCacheCommands_1.OfflineCacheSaveContentRequest:
                await frontApplet.offline.cache.saveContent(commandEvent.command.uid, commandEvent.command.content);
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheSaveContentResult,
                    result: {},
                });
                break;
            case offlineCacheCommands_1.OfflineCacheDeleteContentRequest:
                await frontApplet.offline.cache.deleteContent(commandEvent.command.uid);
                await dispatch({
                    type: offlineCacheCommands_1.OfflineCacheDeleteContentResult,
                    result: {},
                });
                break;
            default:
        }
    });
}
//# sourceMappingURL=handleOfflineCacheRequests.js.map