"use strict";
// SPDX-License-Identifier: Apache-2.0
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectCommandHandler = void 0;
const CommandHandlerDecorator_1 = require("../../../../../core/decorator/CommandHandlerDecorator");
const TransactionService_1 = __importDefault(require("../../../../service/transaction/TransactionService"));
const ConnectCommand_1 = require("./ConnectCommand");
const ConnectCommandError_1 = require("./error/ConnectCommandError");
let ConnectCommandHandler = class ConnectCommandHandler {
    async execute(command) {
        try {
            const handler = TransactionService_1.default.getHandlerClass(command.wallet);
            const debug = command.debug ? command.debug : false;
            const input = command.custodialSettings === undefined
                ? command.HWCSettings === undefined
                    ? command.account
                    : command.HWCSettings
                : command.custodialSettings;
            const registration = await handler.register(input, debug);
            return Promise.resolve(new ConnectCommand_1.ConnectCommandResponse(registration, command.wallet));
        }
        catch (error) {
            throw new ConnectCommandError_1.ConnectCommandError(error);
        }
    }
};
exports.ConnectCommandHandler = ConnectCommandHandler;
exports.ConnectCommandHandler = ConnectCommandHandler = __decorate([
    (0, CommandHandlerDecorator_1.CommandHandler)(ConnectCommand_1.ConnectCommand)
], ConnectCommandHandler);
