"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var response_1 = require("../response");
var core_1 = require("../../../core");
/**
 * Created by Stephane on 02/02/2018.
 */
var DefaultResponseDecoder = /** @class */ (function () {
    function DefaultResponseDecoder() {
        this.apduDecoder = new core_1.APDU.Response.APDUResponseConverter();
    }
    DefaultResponseDecoder.prototype.decode = function (data) {
        var apduResponse = this.apduDecoder.decode(data);
        //        Log.d(TAG, "APDU status: " + Helper.ByteArrayToHexString(apduStatus));
        //        Log.d(TAG, "Expected: " + Helper.ByteArrayToHexString(APDUStatusCode.SUCCESSFUL));
        if (apduResponse.statusEquals(core_1.APDU.APDUStatusCode.SUCCESSFUL)) {
            var payload = apduResponse.getData();
            var response = new response_1.Response(payload);
            return response;
        }
        else {
            throw new Error("Invalid apdu error code: " + core_1.FormatHelper.toHexString(apduResponse.getStatus()) + ". (full =" + core_1.FormatHelper.toHexString(data) + ")");
        }
    };
    return DefaultResponseDecoder;
}());
exports.DefaultResponseDecoder = DefaultResponseDecoder;
