"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const enums_1 = require("../../../enums");
const utils_1 = require("../../../utils");
const schemas = __importStar(require("../schemas"));
const transaction_1 = require("../transaction");
class VoteTransaction extends transaction_1.Transaction {
    static getSchema() {
        return schemas.vote;
    }
    serialize(options) {
        const { data } = this;
        const buff = new utils_1.ByteBuffer(Buffer.alloc(100));
        if (data.asset && data.asset.votes) {
            const voteBytes = data.asset.votes
                .map((vote) => (vote.startsWith("+") ? "01" : "00") + vote.slice(1))
                .join("");
            buff.writeUInt8(data.asset.votes.length);
            buff.writeBuffer(Buffer.from(voteBytes, "hex"));
        }
        return buff;
    }
    deserialize(buf) {
        const { data } = this;
        const votelength = buf.readUInt8();
        data.asset = { votes: [] };
        for (let i = 0; i < votelength; i++) {
            let vote = buf.readBuffer(34).toString("hex");
            vote = (vote[1] === "1" ? "+" : "-") + vote.slice(2);
            if (data.asset && data.asset.votes) {
                data.asset.votes.push(vote);
            }
        }
    }
}
exports.VoteTransaction = VoteTransaction;
VoteTransaction.typeGroup = enums_1.TransactionTypeGroup.Core;
VoteTransaction.type = enums_1.TransactionType.Vote;
VoteTransaction.key = "vote";
VoteTransaction.version = 1;
VoteTransaction.defaultStaticFee = utils_1.BigNumber.make("100000000");
//# sourceMappingURL=vote.js.map