"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const utils_1 = require("./utils");
/**
 * Generic class factory for all of the contract wrapper classes.
 */
class ContractWrapperFactory {
    /**
     * Connstructor to create a contract wrapper factory for the given
     * Arc contract name and wrapper class.
     * @param solidityContract Name of the contract
     * @param wrapper - Class of the contract
     */
    constructor(solidityContractName, wrapper) {
        this.solidityContractName = solidityContractName;
        this.wrapper = wrapper;
    }
    /**
     * Deploy a new instance of the contract and return a wrapper around it.
     * @param rest Optional arguments to the Arc contracts constructor.
     */
    new(...rest) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield this.ensureSolidityContract();
            return new this.wrapper(this.solidityContract).hydrateFromNew(...rest);
        });
    }
    /**
     * Return a wrapper around the contract, hydrated from the given address.
     * Throws an exception if the contract is not found at the given address.
     * @param address
     */
    at(address) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield this.ensureSolidityContract();
            return new this.wrapper(this.solidityContract).hydrateFromAt(address);
        });
    }
    /**
     * Return a wrapper around the contract as deployed by the current version of Arc.js.
     * Note this is usually not needed as the WrapperService provides these
     * wrappers already hydrated.
     */
    deployed() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield this.ensureSolidityContract();
            return new this.wrapper(this.solidityContract).hydrateFromDeployed();
        });
    }
    ensureSolidityContract() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            if (!this.solidityContract) {
                this.solidityContract = yield utils_1.Utils.requireContract(this.solidityContractName);
            }
        });
    }
}
exports.ContractWrapperFactory = ContractWrapperFactory;
//# sourceMappingURL=contractWrapperFactory.js.map