import { decodeAbiParameters, encodeAbiParameters } from "viem";
const CONFIG_COMPONENTS = [
    { name: "tokens", type: "address[]" },
    { name: "spenders", type: "address[]" },
    { name: "consumingTargets", type: "address[]" },
    { name: "consumingSelectors", type: "bytes4[]" },
    { name: "maxApprovalAmounts", type: "uint256[]" },
    { name: "requireAmountMatch", type: "bool" },
];
const ABI = [{ name: "config", type: "tuple", components: CONFIG_COMPONENTS }];
export const approveAndCallBatchTemplate = {
    name: "SharedApproveAndCallBatchPermission",
    address: "0x0000000000000000000000000000000000000000",
    encoder: {
        encode(params) {
            return encodeAbiParameters(ABI, [
                {
                    tokens: params.tokens,
                    spenders: params.spenders,
                    consumingTargets: params.consumingTargets,
                    consumingSelectors: params.consumingSelectors,
                    maxApprovalAmounts: params.maxApprovalAmounts,
                    requireAmountMatch: params.requireAmountMatch,
                },
            ]);
        },
        decode(data) {
            const [config] = decodeAbiParameters(ABI, data);
            return {
                tokens: [...config.tokens],
                spenders: [...config.spenders],
                consumingTargets: [...config.consumingTargets],
                consumingSelectors: [...config.consumingSelectors],
                maxApprovalAmounts: [...config.maxApprovalAmounts],
                requireAmountMatch: config.requireAmountMatch,
            };
        },
    },
    explainer: {
        explain(params) {
            const warnings = [];
            if (params.tokens.length !== params.maxApprovalAmounts.length) {
                warnings.push("tokens and maxApprovalAmounts length mismatch — configuration will revert on-chain");
            }
            if (params.spenders.length === 0 || params.tokens.length === 0) {
                warnings.push("Empty token or spender allowlist — configuration will revert on-chain");
            }
            if (!params.requireAmountMatch) {
                warnings.push("Amount-match disabled — the consuming call may move less than the approved amount");
            }
            return {
                templateName: "SharedApproveAndCallBatchPermission",
                humanReadable: [
                    `Approvable tokens (${params.tokens.length}): ${params.tokens.join(", ")}`,
                    `Approved spenders: ${params.spenders.join(", ")}`,
                    `Consuming targets: ${params.consumingTargets.join(", ")}`,
                    `Consuming selectors: ${params.consumingSelectors.join(", ")}`,
                    `Per-token approval caps: ${params.maxApprovalAmounts.map((a) => a.toString()).join(", ")}`,
                    `Require amount match: ${params.requireAmountMatch ? "yes" : "no"}`,
                ],
                warnings,
            };
        },
    },
};
//# sourceMappingURL=approveAndCallBatch.js.map