"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bosonAccountHandlerIface = void 0;
exports.encodeCreateSeller = encodeCreateSeller;
exports.encodeCreateNewCollection = encodeCreateNewCollection;
exports.encodeUpdateSeller = encodeUpdateSeller;
exports.encodeOptInToSellerUpdate = encodeOptInToSellerUpdate;
exports.encodeCreateBuyer = encodeCreateBuyer;
exports.encodeCreateDisputeResolver = encodeCreateDisputeResolver;
exports.encodeAddFeesToDisputeResolver = encodeAddFeesToDisputeResolver;
exports.encodeAddSellersToAllowList = encodeAddSellersToAllowList;
exports.encodeRemoveFeesFromDisputeResolver = encodeRemoveFeesFromDisputeResolver;
exports.encodeRemoveSellersFromAllowList = encodeRemoveSellersFromAllowList;
exports.encodeUpdateDisputeResolver = encodeUpdateDisputeResolver;
exports.encodeOptInToDisputeResolverUpdate = encodeOptInToDisputeResolverUpdate;
exports.createSellerArgsToStruct = createSellerArgsToStruct;
exports.createCollectionArgsToStruct = createCollectionArgsToStruct;
exports.updateSellerArgsToStruct = updateSellerArgsToStruct;
exports.encodeIsSellerSaltAvailable = encodeIsSellerSaltAvailable;
exports.decodeIsSellerSaltAvailable = decodeIsSellerSaltAvailable;
exports.encodeCalculateCollectionAddress = encodeCalculateCollectionAddress;
exports.decodeCalculateCollectionAddress = decodeCalculateCollectionAddress;
exports.encodeAddRoyaltyRecipients = encodeAddRoyaltyRecipients;
exports.encodeUpdateRoyaltyRecipients = encodeUpdateRoyaltyRecipients;
exports.encodeRemoveRoyaltyRecipients = encodeRemoveRoyaltyRecipients;
exports.encodeGetRoyaltyRecipients = encodeGetRoyaltyRecipients;
exports.decodeGetRoyaltyRecipients = decodeGetRoyaltyRecipients;
const abi_1 = require("@ethersproject/abi");
const strings_1 = require("@ethersproject/strings");
const types_1 = require("./types");
const constants_1 = require("@ethersproject/constants");
const handler_1 = require("./handler");
exports.bosonAccountHandlerIface = new abi_1.Interface(types_1.abis.IBosonAccountHandlerABI);
function encodeCreateSeller(seller, collectionSalt) {
    const sellerArgs = createSellerArgsToStruct(seller, collectionSalt);
    return exports.bosonAccountHandlerIface.encodeFunctionData("createSeller", [
        sellerArgs.sellerStruct,
        sellerArgs.authTokenStruct,
        sellerArgs.voucherInitValues
    ]);
}
function encodeCreateNewCollection(collection) {
    const collectionArgs = createCollectionArgsToStruct(collection);
    return exports.bosonAccountHandlerIface.encodeFunctionData("createNewCollection", [
        collectionArgs.externalId,
        collectionArgs.voucherInitValues
    ]);
}
function encodeUpdateSeller(seller) {
    const sellerArgs = updateSellerArgsToStruct(seller);
    return exports.bosonAccountHandlerIface.encodeFunctionData("updateSeller", [
        sellerArgs.sellerStruct,
        sellerArgs.authTokenStruct
    ]);
}
function encodeOptInToSellerUpdate(seller) {
    const fieldsToUpdate = [];
    Object.entries(types_1.SellerUpdateFields).forEach(([key, value]) => {
        if (seller.fieldsToUpdate[key]) {
            fieldsToUpdate.push(value);
        }
    });
    return exports.bosonAccountHandlerIface.encodeFunctionData("optInToSellerUpdate", [
        seller.id,
        fieldsToUpdate
    ]);
}
function encodeCreateBuyer(buyer) {
    const buyerStruct = argsToBuyerStruct(buyer);
    return exports.bosonAccountHandlerIface.encodeFunctionData("createBuyer", [
        buyerStruct
    ]);
}
function encodeCreateDisputeResolver(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("createDisputeResolver", [
        createDisputeResolverArgsToDisputeResolverStruct(args),
        args.fees,
        args.sellerAllowList || []
    ]);
}
function encodeAddFeesToDisputeResolver(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("addFeesToDisputeResolver", [args.disputeResolverId, args.fees]);
}
function encodeAddSellersToAllowList(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("addSellersToAllowList", [
        args.disputeResolverId,
        args.sellerAllowList
    ]);
}
function encodeRemoveFeesFromDisputeResolver(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("removeFeesFromDisputeResolver", [args.disputeResolverId, args.feeTokenAddresses]);
}
function encodeRemoveSellersFromAllowList(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("removeSellersFromAllowList", [args.disputeResolverId, args.sellerAllowList]);
}
function encodeUpdateDisputeResolver(disputeResolver) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("updateDisputeResolver", [
        disputeResolver
    ]);
}
function encodeOptInToDisputeResolverUpdate(disputeResolver) {
    const fieldsToUpdate = [];
    Object.entries(types_1.DisputeResolverUpdateFields).forEach(([key, value]) => {
        if (disputeResolver.fieldsToUpdate[key]) {
            fieldsToUpdate.push(value);
        }
    });
    return exports.bosonAccountHandlerIface.encodeFunctionData("optInToDisputeResolverUpdate", [disputeResolver.id, fieldsToUpdate]);
}
// TODO: add a unit test for collectionId
function createSellerArgsToStruct(args, collectionSalt) {
    const { authTokenId, authTokenType, contractUri, royaltyPercentage } = args, sellerStructArgs = __rest(args, ["authTokenId", "authTokenType", "contractUri", "royaltyPercentage"]);
    return {
        sellerStruct: argsToSellerStruct(sellerStructArgs),
        authTokenStruct: {
            tokenId: authTokenId,
            tokenType: authTokenType
        },
        voucherInitValues: {
            contractURI: contractUri,
            royaltyPercentage,
            collectionSalt
        }
    };
}
function createCollectionArgsToStruct(args) {
    const { collectionId, contractUri } = args;
    const collectionSalt = args.collectionSalt ||
        (0, strings_1.formatBytes32String)(collectionId || handler_1.INITIAL_COLLECTION_ID);
    return {
        externalId: collectionId,
        voucherInitValues: {
            contractURI: contractUri,
            royaltyPercentage: "0", // useless after protocol v2.4.0
            collectionSalt
        }
    };
}
function updateSellerArgsToStruct(args) {
    const { authTokenId, authTokenType } = args, sellerStructArgs = __rest(args, ["authTokenId", "authTokenType"]);
    return {
        sellerStruct: argsToSellerStruct(sellerStructArgs),
        authTokenStruct: {
            tokenId: authTokenId,
            tokenType: authTokenType
        }
    };
}
function argsToSellerStruct(args) {
    return Object.assign({ 
        // NOTE: It doesn't matter which values we set for `id` and `active` here
        // as they will be overridden by the contract. But to conform to the struct
        // we need to set some arbitrary values.
        id: "0", active: true, clerk: constants_1.AddressZero }, args);
}
function argsToBuyerStruct(args) {
    return Object.assign({ 
        // NOTE: It doesn't matter which values we set for `id` and `active` here
        // as they will be overridden by the contract. But to conform to the struct
        // we need to set some arbitrary values.
        id: "0", active: true }, args);
}
function createDisputeResolverArgsToDisputeResolverStruct(args) {
    return Object.assign(Object.assign({ 
        // NOTE: It doesn't matter which values we set for `id` and `active` here
        // as they will be overridden by the contract. But to conform to the struct
        // we need to set some arbitrary values.
        id: "0", active: true, clerk: constants_1.AddressZero }, args), { escalationResponsePeriod: types_1.utils.timestamp.msToSec(args.escalationResponsePeriodInMS) });
}
function encodeIsSellerSaltAvailable(adminAddress, salt) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("isSellerSaltAvailable", [
        adminAddress,
        salt
    ]);
}
function decodeIsSellerSaltAvailable(result) {
    const [isAvailable] = exports.bosonAccountHandlerIface.decodeFunctionResult("isSellerSaltAvailable", result);
    return isAvailable;
}
function encodeCalculateCollectionAddress(sellerId, collectionSalt) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("calculateCollectionAddress", [sellerId, collectionSalt]);
}
function decodeCalculateCollectionAddress(result) {
    const [collectionAddress, isAvailable] = exports.bosonAccountHandlerIface.decodeFunctionResult("calculateCollectionAddress", result);
    return { collectionAddress, isAvailable };
}
function encodeAddRoyaltyRecipients(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("addRoyaltyRecipients", [
        args.sellerId,
        args.royaltyRecipients
    ]);
}
function encodeUpdateRoyaltyRecipients(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("updateRoyaltyRecipients", [args.sellerId, args.royaltyRecipientIds, args.royaltyRecipients]);
}
function encodeRemoveRoyaltyRecipients(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("removeRoyaltyRecipients", [args.sellerId, args.royaltyRecipientIds]);
}
function encodeGetRoyaltyRecipients(args) {
    return exports.bosonAccountHandlerIface.encodeFunctionData("getRoyaltyRecipients", [
        args.sellerId
    ]);
}
function decodeGetRoyaltyRecipients(result) {
    const [royaltyRecipients] = exports.bosonAccountHandlerIface.decodeFunctionResult("getRoyaltyRecipients", result);
    return royaltyRecipients;
}
//# sourceMappingURL=interface.js.map