"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
const darc_1 = require("../../darc");
const network_1 = require("../../network");
// tslint:disable-next-line
const varint = require("varint");
/**
 * Arrange arguments for a config contract, ie. provide a meaningful
 * representation of its arguments.
 */
class ConfigBeautifier {
    static Spawn(args) {
        const res = Array();
        args.forEach((arg) => {
            switch (arg.name) {
                case "darc":
                    const darc = darc_1.Darc.decode(arg.value);
                    res.push({ name: "darc", value: darc.description.toString(), full: darc.toString() });
                    break;
                case "block_interval":
                    res.push({ name: "block_interval", value: `${varint.decode(arg.value, 0) / 1e6} ms` });
                    break;
                case "max_block_size":
                    res.push({ name: "max_block_size", value: `${varint.decode(arg.value, 0)} bytes` });
                    break;
                case "roster":
                    const r = network_1.Roster.decode(arg.value);
                    res.push({ name: "roster", value: r.id.toString("hex"), full: r.toTOML() });
                    break;
                case "trie_nonce":
                    res.push({ name: "trie_nonce", value: `${varint.decode(arg.value, 0)}` });
                    break;
                case "darc_contracts":
                    res.push({ name: "darc_contracts", value: arg.value.toString("hex") });
                    break;
                default:
                    res.push({ name: arg.name, value: "unspecified", full: arg.value.toString("hex") });
                    break;
            }
        });
        return res;
    }
    static Invoke(args) {
        const res = Array();
        args.forEach((arg) => {
            switch (arg.name) {
                case "config":
                    const config = __1.ChainConfig.decode(arg.value);
                    res.push({ name: "darc", value: "chain config", full: config.toString() });
                    break;
                default:
                    res.push({ name: arg.name, value: "unspecified", full: arg.value.toString("hex") });
                    break;
            }
        });
        return res;
    }
}
exports.ConfigBeautifier = ConfigBeautifier;
