"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const long_1 = tslib_1.__importDefault(require("long"));
const darc_1 = require("../../darc");
/**
 * Arrange arguments for a Coin contract, ie. provide a meaningful
 * representation of its arguments.
 */
class CoinBeautifier {
    static Spawn(args) {
        const res = Array();
        args.forEach((arg) => {
            switch (arg.name) {
                case "public":
                    res.push({ name: arg.name, value: arg.value.toString("hex") });
                    break;
                case "coinID":
                    res.push({ name: arg.name, value: arg.value.toString("hex") });
                    break;
                case "darcID":
                    try {
                        const darc = darc_1.Darc.decode(arg.value);
                        res.push({ name: "darc", value: darc.description.toString(), full: darc.toString() });
                    }
                    catch (e) {
                        // case for the block d487b398d47cb2893baa2bf17dd7b00511840b46f58563d44d67bffca43d5de0
                        res.push({ full: `error: ${e} - darc: ${arg.value.toString()}`,
                            name: "darc", value: "failed to decode" });
                    }
                    break;
                case "type":
                    res.push({ name: arg.name, 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 "coins":
                    const coins = long_1.default.fromBytesLE(Array.from(arg.value));
                    let label = "coin";
                    if (coins.compare(1) > 0) {
                        label = "coins";
                    }
                    res.push({ name: "coins", value: `${coins} ${label}` });
                    break;
                case "destination":
                    res.push({ name: "destination", value: arg.value.toString("hex") });
                    break;
                default:
                    res.push({ name: arg.name, value: "unspecified", full: arg.value.toString("hex") });
                    break;
            }
        });
        return res;
    }
}
exports.CoinBeautifier = CoinBeautifier;
