"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.restoreAppDataUseCase = void 0;
const rxjs_1 = require("rxjs");
const types_1 = require("./types");
/**
 * Restores the application data for a specific app on a Ledger device.
 *
 * @param appName - The name of the application to restore.
 * @param deviceModelId - The device model ID.
 * @param storageProvider - The storage provider object used for retrieving the backup data.
 * @param restoreAppDataFn - The function used to restore the app data.
 * @returns An observable that emits RestoreAppDataEvent according to the restore process.
 * @throws {RestoreAppDataError}
 */
function restoreAppDataUseCase(appName, deviceModelId, storageProvider, restoreAppDataFn) {
    const obs = (0, rxjs_1.from)(storageProvider.getItem(`${deviceModelId}-${appName}`)).pipe((0, rxjs_1.switchMap)((appStorage) => {
        if (!appStorage) {
            return (0, rxjs_1.of)({
                type: types_1.RestoreAppDataEventType.NoAppDataToRestore,
            });
        }
        return restoreAppDataFn(appStorage.appData);
    }));
    return obs;
}
exports.restoreAppDataUseCase = restoreAppDataUseCase;
//# sourceMappingURL=restoreAppDataUseCase.js.map