"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bosonExchangeCommitHandlerIface = exports.bosonExchangeHandlerIface = void 0;
exports.encodeCommitToOffer = encodeCommitToOffer;
exports.encodeCommitToBuyerOffer = encodeCommitToBuyerOffer;
exports.encodeCommitToConditionalOffer = encodeCommitToConditionalOffer;
exports.encodeCreateOfferAndCommit = encodeCreateOfferAndCommit;
exports.fullOfferArgsToStruct = fullOfferArgsToStruct;
exports.encodeCompleteExchange = encodeCompleteExchange;
exports.encodeCompleteExchangeBatch = encodeCompleteExchangeBatch;
exports.encodeRevokeVoucher = encodeRevokeVoucher;
exports.encodeCancelVoucher = encodeCancelVoucher;
exports.encodeExpireVoucher = encodeExpireVoucher;
exports.encodeRedeemVoucher = encodeRedeemVoucher;
exports.argsToSellerOfferStruct = argsToSellerOfferStruct;
const common_1 = require("@bosonprotocol/common");
const abi_1 = require("@ethersproject/abi");
const address_1 = require("@ethersproject/address");
const constants_1 = require("@ethersproject/constants");
const interface_1 = require("../offers/interface");
const interface_2 = require("../groups/interface");
exports.bosonExchangeHandlerIface = new abi_1.Interface(common_1.abis.IBosonExchangeHandlerABI);
exports.bosonExchangeCommitHandlerIface = new abi_1.Interface(common_1.abis.IBosonExchangeCommitHandlerABI);
function encodeCommitToOffer(buyer, offerId) {
    return exports.bosonExchangeCommitHandlerIface.encodeFunctionData("commitToOffer", [
        buyer,
        offerId
    ]);
}
function encodeCommitToBuyerOffer(offerId, sellerParams) {
    return exports.bosonExchangeCommitHandlerIface.encodeFunctionData("commitToBuyerOffer", [offerId, argsToSellerOfferStruct(sellerParams)]);
}
function encodeCommitToConditionalOffer(buyer, offerId, tokenId) {
    return exports.bosonExchangeCommitHandlerIface.encodeFunctionData("commitToConditionalOffer", [buyer, offerId, tokenId]);
}
function encodeCreateOfferAndCommit(args) {
    return exports.bosonExchangeCommitHandlerIface.encodeFunctionData("createOfferAndCommit", fullOfferArgsToStructs(args));
}
function fullOfferArgsToStructs(args) {
    return [
        fullOfferArgsToStruct(args),
        args.offerCreator,
        args.committer,
        args.signature,
        args.conditionalTokenId || "0",
        [
            args.sellerOfferParams.collectionIndex,
            [
                args.sellerOfferParams.royaltyInfo.recipients,
                args.sellerOfferParams.royaltyInfo.bps
            ],
            args.sellerOfferParams.mutualizerAddress
        ]
    ];
}
function fullOfferArgsToStruct(args) {
    const feeLimit = args.feeLimit !== undefined ? args.feeLimit : args.price;
    return [
        // fullOffer
        (0, interface_1.argsToOfferStruct)(args),
        (0, interface_1.argsToOfferDatesStruct)(args),
        (0, interface_1.argsToOfferDurationsStruct)(args),
        (0, interface_1.argsToDRParametersStruct)(args),
        (0, interface_2.conditionArgsToStructs)(args.condition),
        args.agentId,
        feeLimit.toString(),
        args.useDepositedFunds
    ];
}
function encodeCompleteExchange(exchangeId) {
    return exports.bosonExchangeHandlerIface.encodeFunctionData("completeExchange", [
        exchangeId
    ]);
}
function encodeCompleteExchangeBatch(exchangeIds) {
    return exports.bosonExchangeHandlerIface.encodeFunctionData("completeExchangeBatch", [
        exchangeIds
    ]);
}
function encodeRevokeVoucher(exchangeId) {
    return exports.bosonExchangeHandlerIface.encodeFunctionData("revokeVoucher", [
        exchangeId
    ]);
}
function encodeCancelVoucher(exchangeId) {
    return exports.bosonExchangeHandlerIface.encodeFunctionData("cancelVoucher", [
        exchangeId
    ]);
}
function encodeExpireVoucher(exchangeId) {
    return exports.bosonExchangeHandlerIface.encodeFunctionData("expireVoucher", [
        exchangeId
    ]);
}
function encodeRedeemVoucher(exchangeId) {
    return exports.bosonExchangeHandlerIface.encodeFunctionData("redeemVoucher", [
        exchangeId
    ]);
}
function argsToSellerOfferStruct(args) {
    const royaltyInfo = args.royaltyInfo !== undefined
        ? Object.assign(Object.assign({}, args.royaltyInfo), { recipients: args.royaltyInfo.recipients.map((recipient) => (0, address_1.getAddress)(recipient.toLowerCase())) }) : {
        recipients: [],
        bps: []
    };
    return {
        collectionIndex: args.collectionIndex || 0,
        royaltyInfo,
        mutualizerAddress: args.mutualizerAddress
            ? (0, address_1.getAddress)(args.mutualizerAddress.toLowerCase())
            : constants_1.AddressZero
    };
}
//# sourceMappingURL=interface.js.map