"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseChangeReturns = void 0;
var Prefix;
(function (Prefix) {
    Prefix[Prefix["Block"] = 1] = "Block";
    Prefix[Prefix["Transaction"] = 2] = "Transaction";
    Prefix[Prefix["Storage"] = 112] = "Storage";
    Prefix[Prefix["HeaderHashList"] = 128] = "HeaderHashList";
    Prefix[Prefix["CurrentBlock"] = 192] = "CurrentBlock";
    Prefix[Prefix["CurrentHeader"] = 193] = "CurrentHeader";
    Prefix[Prefix["ContractID"] = 194] = "ContractID";
})(Prefix || (Prefix = {}));
const addPrefix = (prefix, key) => Buffer.concat([Buffer.from([prefix]), key]);
const addPrefixToKey = (type, key) => {
    switch (type) {
        case 'block':
            return addPrefix(Prefix.Block, key);
        case 'transaction':
            return addPrefix(Prefix.Transaction, key);
        case 'storage':
            return addPrefix(Prefix.Storage, key);
        case 'headerHashList':
            return addPrefix(Prefix.HeaderHashList, key);
        default:
            throw new Error(`Invalid type: ${type}`);
    }
};
exports.parseChangeReturns = (changes) => changes.map(parseChangeReturn);
const parseChangeReturn = (change) => {
    switch (change.type) {
        case 'Added':
            return {
                type: 'put',
                key: addPrefixToKey(change.itemType, change.key),
                value: change.value,
            };
        case 'Changed':
            return {
                type: 'put',
                key: addPrefixToKey(change.itemType, change.key),
                value: change.value,
            };
        case 'Deleted':
            return {
                type: 'del',
                key: addPrefixToKey(change.itemType, change.key),
            };
        default:
            throw new Error('Invalid Change Type found');
    }
};

//# sourceMappingURL=changes.js.map
