"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.raiseDispute = raiseDispute;
exports.retractDispute = retractDispute;
exports.extendDisputeTimeout = extendDisputeTimeout;
exports.expireDispute = expireDispute;
exports.expireDisputeBatch = expireDisputeBatch;
exports.resolveDispute = resolveDispute;
exports.escalateDispute = escalateDispute;
exports.decideDispute = decideDispute;
exports.refuseEscalatedDispute = refuseEscalatedDispute;
exports.expireEscalatedDispute = expireEscalatedDispute;
exports.signResolutionProposal = signResolutionProposal;
const interface_1 = require("./interface");
const signature_1 = require("../utils/signature");
// Implementation
function raiseDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeRaiseDispute)(args)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function retractDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeRetractDispute)(args.exchangeId)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function extendDisputeTimeout(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeExtendDisputeTimeout)(args)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function expireDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeExpireDispute)(args.exchangeId)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function expireDisputeBatch(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeExpireDisputeBatch)(args.exchangeIds)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function resolveDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeResolveDispute)(args)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function escalateDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeEscalateDispute)(args.exchangeId)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function decideDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeDecideDispute)(args)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function refuseEscalatedDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeRefuseEscalatedDispute)(args.exchangeId)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
// Implementation
function expireEscalatedDispute(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = {
            to: args.contractAddress,
            data: (0, interface_1.encodeExpireEscalatedDispute)(args.exchangeId)
        };
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
function signResolutionProposal(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const customSignatureType = {
            Resolution: [
                { name: "exchangeId", type: "uint256" },
                { name: "buyerPercentBasisPoints", type: "uint256" }
            ]
        };
        const message = {
            exchangeId: args.exchangeId.toString(),
            buyerPercentBasisPoints: args.buyerPercentBasisPoints.toString()
        };
        const signatureArgs = {
            message,
            customSignatureType,
            web3Lib: args.web3Lib,
            verifyingContractAddress: args.contractAddress,
            chainId: args.chainId,
            primaryType: "Resolution"
        };
        if (args.returnTypedDataToSign) {
            return (0, signature_1.prepareDataSignatureParameters)(Object.assign(Object.assign({}, signatureArgs), { returnTypedDataToSign: true }));
        }
        else {
            return (0, signature_1.prepareDataSignatureParameters)(Object.assign(Object.assign({}, signatureArgs), { returnTypedDataToSign: false }));
        }
    });
}
//# sourceMappingURL=handler.js.map