"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMarkAsNotMatchRequest = void 0;
var react_1 = require("react");
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var useIsMountedRef_1 = require("../useIsMountedRef");
var MdmModuleContext_1 = require("../../contexts/MdmModuleContext");
var useMarkAsNotMatchRequest = function (_a) {
    var entities = _a.entities, entity = _a.entity, onFinishRequest = _a.onFinishRequest, onStartRequest = _a.onStartRequest, onSuccess = _a.onSuccess, _b = _a.onError, onError = _b === void 0 ? ramda_1.identity : _b;
    var isMountedRef = (0, useIsMountedRef_1.useIsMountedRef)();
    var _c = (0, react_1.useState)(false), isPending = _c[0], setIsPending = _c[1];
    var tenant = (0, MdmModuleContext_1.useMdmTenant)();
    var dtssPath = (0, MdmModuleContext_1.useMdmDtssPath)();
    var sendMarkAsNotMatchRequest = (0, react_1.useCallback)(function () {
        onStartRequest === null || onStartRequest === void 0 ? void 0 : onStartRequest();
        setIsPending(true);
        var params = { dtssPath: dtssPath, customerTenant: tenant, entity: entity, entities: entities };
        ((0, mdm_sdk_1.isDataTenantEntity)(entity) ? (0, mdm_sdk_1.markDataTenantEntityAsNotMatch)(params) : (0, mdm_sdk_1.markMixedEntitiesAsNotMatches)(params))
            .then(function () {
            onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
        })
            .catch(onError)
            .finally(function () {
            onFinishRequest === null || onFinishRequest === void 0 ? void 0 : onFinishRequest();
            if (isMountedRef.current)
                setIsPending(false);
        });
    }, [dtssPath, entities, entity, isMountedRef, onFinishRequest, onStartRequest, onError, onSuccess, tenant]);
    return { isPending: isPending, sendMarkAsNotMatchRequest: sendMarkAsNotMatchRequest };
};
exports.useMarkAsNotMatchRequest = useMarkAsNotMatchRequest;
