import { useCallback, useState } from 'react';
import { identity } from 'ramda';
import { isDataTenantEntity, markDataTenantEntityAsNotMatch, markMixedEntitiesAsNotMatches } from '@reltio/mdm-sdk';
import { useIsMountedRef } from '../useIsMountedRef';
import { useMdmDtssPath, useMdmTenant } from '../../contexts/MdmModuleContext';
export 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 ? identity : _b;
    var isMountedRef = useIsMountedRef();
    var _c = useState(false), isPending = _c[0], setIsPending = _c[1];
    var tenant = useMdmTenant();
    var dtssPath = useMdmDtssPath();
    var sendMarkAsNotMatchRequest = useCallback(function () {
        onStartRequest === null || onStartRequest === void 0 ? void 0 : onStartRequest();
        setIsPending(true);
        var params = { dtssPath: dtssPath, customerTenant: tenant, entity: entity, entities: entities };
        (isDataTenantEntity(entity) ? markDataTenantEntityAsNotMatch(params) : 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 };
};
