"use strict";
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("@polkadot/util");
const ContractRegistry_1 = __importDefault(require("./ContractRegistry"));
class ContractAbi extends ContractRegistry_1.default {
    constructor(registry, abi) {
        super(registry, abi);
        [this.abi, this.constructors, this.messages] = this.decodeAbi(abi);
    }
    decodeAbi(abiPre) {
        this.validateAbi(abiPre);
        const abi = this.convertAbi(abiPre);
        const constructors = abi.contract.constructors.map((constructor, index) => {
            return this.createMessage(`constructor ${index}`, constructor);
        });
        const messages = abi.contract.messages.reduce((result, message) => {
            const name = util_1.stringCamelCase(message.name);
            return Object.assign(Object.assign({}, result), { [name]: this.createMessage(`messages.${name}`, message) });
        }, {});
        return [abi, constructors, messages];
    }
}
exports.default = ContractAbi;
