"use strict";
// Copyright 2021-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateStrongholdSnapshotV2ToV3 = exports.SecretManagerMethodHandler = void 0;
const __1 = require("..");
const bindings_1 = require("../bindings");
Object.defineProperty(exports, "migrateStrongholdSnapshotV2ToV3", { enumerable: true, get: function () { return bindings_1.migrateStrongholdSnapshotV2ToV3; } });
/** The MethodHandler which sends the commands to the Rust backend. */
class SecretManagerMethodHandler {
    /**
     * @param methodHandler The Rust method handler created in `SecretManagerMethodHandler.create()`.
     */
    constructor(methodHandler) {
        this.methodHandler = methodHandler;
    }
    /**
     * @param options A secret manager type or a secret manager method handler.
     */
    static create(options) {
        try {
            const methodHandler = (0, bindings_1.createSecretManager)(JSON.stringify(options));
            return new SecretManagerMethodHandler(methodHandler);
        }
        catch (error) {
            throw (0, __1.errorHandle)(error);
        }
    }
    /**
     * Call a secret manager method.
     *
     * @param method One of the supported secret manager methods.
     * @returns The JSON response of the method.
     */
    async callMethod(method) {
        return (0, bindings_1.callSecretManagerMethod)(this.methodHandler, JSON.stringify(method)).catch((error) => {
            throw (0, __1.errorHandle)(error);
        });
    }
}
exports.SecretManagerMethodHandler = SecretManagerMethodHandler;
//# sourceMappingURL=secret-manager-method-handler.js.map