import { createHandlerChainRunner, Handler } from "@insite/client-framework/HandlerCreator";
import { sendTracking as sendTrackingApi } from "@insite/client-framework/Services/ProductRecommendationsService";
import log from "@insite/client-framework/Store/Components/ProductRecommendations/Handlers/Log";

type HandlerType = Handler<{ json: string }>;

export const LogRequest: HandlerType = ({ dispatch, parameter: { json } }) => {
    dispatch(log({ message: "Send Tracking: ", data: json }));
};

export const CallApi: HandlerType = ({ parameter: { json } }) => {
    sendTrackingApi(json);
};

export const chain = [LogRequest, CallApi];

const sendTracking = createHandlerChainRunner(chain, "SendTracking");
export default sendTracking;
