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

type HandlerType = ApiHandlerNoParameter<SpreedlyConfig>;

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

export const DispatchCompleteLoadSpreedlyConfig: HandlerType = props => {
    props.dispatch({
        type: "Context/CompleteLoadSpreedlyConfig",
        spreedlyConfig: props.apiResult,
    });
};

export const chain = [GetSpreedlyConfig, DispatchCompleteLoadSpreedlyConfig];

const loadSpreedlyConfig = createHandlerChainRunnerOptionalParameter(chain, {}, "LoadSpreedlyConfig");
export default loadSpreedlyConfig;
