"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());
    });
};
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.DisputesMixin = void 0;
const base_core_sdk_1 = require("./../mixins/base-core-sdk");
const handler_1 = require("./handler");
const subgraph_1 = require("./subgraph");
class DisputesMixin extends base_core_sdk_1.BaseCoreSDK {
    /* -------------------------------------------------------------------------- */
    /*                           Dispute related methods                          */
    /* -------------------------------------------------------------------------- */
    /**
     * Returns dispute entity from subgraph.
     * @param disputeId - ID of dispute entity.
     * @param queryVars - Optional query variables to skip, order or filter.
     * @returns Dispute entity from subgraph.
     */
    getDisputeById(disputeId, queryVars) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, subgraph_1.getDisputeById)(this._subgraphUrl, disputeId, queryVars);
        });
    }
    /**
     * Returns dispute entities from subgraph.
     * @param queryVars - Optional query variables to skip, order or filter.
     * @returns Dispute entities from subgraph.
     */
    getDisputes(queryVars) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, subgraph_1.getDisputes)(this._subgraphUrl, queryVars);
        });
    }
    raiseDispute(exchangeId, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const raiseArgs = {
                exchangeId,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.raiseDispute)(Object.assign(Object.assign({}, raiseArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.raiseDispute)(Object.assign(Object.assign({}, raiseArgs), { returnTxInfo: false }));
            }
        });
    }
    retractDispute(exchangeId, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const retractArgs = {
                exchangeId,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.retractDispute)(Object.assign(Object.assign({}, retractArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.retractDispute)(Object.assign(Object.assign({}, retractArgs), { returnTxInfo: false }));
            }
        });
    }
    extendDisputeTimeout(exchangeId, newDisputeTimeout, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const extendArgs = {
                exchangeId,
                newDisputeTimeout,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.extendDisputeTimeout)(Object.assign(Object.assign({}, extendArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.extendDisputeTimeout)(Object.assign(Object.assign({}, extendArgs), { returnTxInfo: false }));
            }
        });
    }
    expireDispute(exchangeId, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const expireArgs = {
                exchangeId,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.expireDispute)(Object.assign(Object.assign({}, expireArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.expireDispute)(Object.assign(Object.assign({}, expireArgs), { returnTxInfo: false }));
            }
        });
    }
    expireDisputeBatch(exchangeIds, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const batchArgs = {
                exchangeIds,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.expireDisputeBatch)(Object.assign(Object.assign({}, batchArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.expireDisputeBatch)(Object.assign(Object.assign({}, batchArgs), { returnTxInfo: false }));
            }
        });
    }
    resolveDispute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            const { returnTxInfo } = args;
            const resolveArgs = "signature" in args
                ? {
                    exchangeId: args.exchangeId,
                    buyerPercentBasisPoints: args.buyerPercentBasisPoints,
                    signature: args.signature,
                    contractAddress: this._protocolDiamond,
                    web3Lib: this._web3Lib
                }
                : {
                    exchangeId: args.exchangeId,
                    buyerPercentBasisPoints: args.buyerPercentBasisPoints,
                    sigR: args.sigR,
                    sigS: args.sigS,
                    sigV: args.sigV,
                    contractAddress: this._protocolDiamond,
                    web3Lib: this._web3Lib
                };
            if (returnTxInfo === true) {
                return (0, handler_1.resolveDispute)(Object.assign(Object.assign({}, resolveArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.resolveDispute)(Object.assign(Object.assign({}, resolveArgs), { returnTxInfo: false }));
            }
        });
    }
    escalateDispute(exchangeId, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const escalateArgs = {
                exchangeId,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.escalateDispute)(Object.assign(Object.assign({}, escalateArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.escalateDispute)(Object.assign(Object.assign({}, escalateArgs), { returnTxInfo: false }));
            }
        });
    }
    decideDispute(exchangeId, buyerPercent, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const decideArgs = {
                exchangeId,
                buyerPercent,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.decideDispute)(Object.assign(Object.assign({}, decideArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.decideDispute)(Object.assign(Object.assign({}, decideArgs), { returnTxInfo: false }));
            }
        });
    }
    refuseEscalatedDispute(exchangeId, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const refuseArgs = {
                exchangeId,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.refuseEscalatedDispute)(Object.assign(Object.assign({}, refuseArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.refuseEscalatedDispute)(Object.assign(Object.assign({}, refuseArgs), { returnTxInfo: false }));
            }
        });
    }
    expireEscalatedDispute(exchangeId, returnTxInfo) {
        return __awaiter(this, void 0, void 0, function* () {
            const expireEscalatedArgs = {
                exchangeId,
                contractAddress: this._protocolDiamond,
                web3Lib: this._web3Lib
            };
            if (returnTxInfo === true) {
                return (0, handler_1.expireEscalatedDispute)(Object.assign(Object.assign({}, expireEscalatedArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.expireEscalatedDispute)(Object.assign(Object.assign({}, expireEscalatedArgs), { returnTxInfo: false }));
            }
        });
    }
    signDisputeResolutionProposal(args) {
        return __awaiter(this, void 0, void 0, function* () {
            const { returnTypedDataToSign } = args, argsWithoutReturnTypedDataToSign = __rest(args, ["returnTypedDataToSign"]);
            const params = Object.assign(Object.assign({}, argsWithoutReturnTypedDataToSign), { web3Lib: this._web3Lib, contractAddress: this._protocolDiamond, chainId: this._chainId });
            if (returnTypedDataToSign === true) {
                return (0, handler_1.signResolutionProposal)(Object.assign(Object.assign({}, params), { returnTypedDataToSign: true }));
            }
            else {
                return (0, handler_1.signResolutionProposal)(Object.assign(Object.assign({}, params), { returnTypedDataToSign: false }));
            }
        });
    }
}
exports.DisputesMixin = DisputesMixin;
//# sourceMappingURL=mixin.js.map