import {
    ApiHandlerNoParameter,
    createHandlerChainRunnerOptionalParameter,
} from "@insite/client-framework/HandlerCreator";
import { getGooglePayConfig, GooglePayConfig } from "@insite/client-framework/Services/SettingsService";

type HandlerType = ApiHandlerNoParameter<GooglePayConfig>;

export const GetGooglePayConfig: HandlerType = async props => {
    props.apiResult = await getGooglePayConfig();
};

export const DispatchCompleteLoadGooglePayConfig: HandlerType = props => {
    props.dispatch({
        type: "Context/CompleteLoadGooglePayConfig",
        googlePayConfig: props.apiResult,
    });
};

export const chain = [GetGooglePayConfig, DispatchCompleteLoadGooglePayConfig];

const loadGooglePayConfig = createHandlerChainRunnerOptionalParameter(chain, {}, "LoadGooglePayConfig");
export default loadGooglePayConfig;
