"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.burnPremintedVouchers = burnPremintedVouchers;
exports.owner = owner;
exports.isTrustedForwarder = isTrustedForwarder;
exports.getAvailablePreMints = getAvailablePreMints;
exports.getRangeByOfferId = getRangeByOfferId;
exports.preMint = preMint;
exports.transferFrom = transferFrom;
exports.isApprovedForAll = isApprovedForAll;
exports.setContractURI = setContractURI;
exports.callExternalContract = callExternalContract;
exports.setApprovalForAllToContract = setApprovalForAllToContract;
exports.withdrawToProtocol = withdrawToProtocol;
const interface_1 = require("./interface");
function burnPremintedVouchers(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeBurnPremintedVouchers)(args.offerId, args.amount)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
function owner(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: (0, interface_1.encodeOwner)()
        });
        return (0, interface_1.decodeOwner)(result);
    });
}
function isTrustedForwarder(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: (0, interface_1.encodeIsTrustedForwarder)(args.forwarder)
        });
        return (0, interface_1.decodeIsTrustedForwarder)(result);
    });
}
function getAvailablePreMints(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: (0, interface_1.encodeGetAvailablePreMints)(args.offerId)
        });
        const [count] = (0, interface_1.decodeGetAvailablePreMints)(result);
        return String(count);
    });
}
function getRangeByOfferId(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: (0, interface_1.encodeGetRangeByOfferId)(args.offerId)
        });
        const [range] = (0, interface_1.decodeGetRangeByOfferId)(result);
        return {
            start: range.start,
            length: range._length,
            minted: range.minted,
            lastBurnedTokenId: range.lastBurnedTokenId
        };
    });
}
function preMint(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodePreMint)(args.offerId, args.amount)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
function transferFrom(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeTransferFrom)(args.from, args.to, args.tokenId)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
function isApprovedForAll(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: (0, interface_1.encodeIsApprovedForAll)(args.owner, args.operator)
        });
        const [isApproved] = (0, interface_1.decodeIsApprovedForAll)(result);
        return isApproved;
    });
}
function setContractURI(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeSetContractURI)(args.contractURI)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
function callExternalContract(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeCallExternalContract)(args.to, args.data)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
function setApprovalForAllToContract(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeSetApprovalForAllToContract)(args.operator, args.approved)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
function withdrawToProtocol(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeWithdrawToProtocol)(args.tokenList)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
//# sourceMappingURL=handler.js.map