package cz.moneta.test.dsl.openapi.smeonboarding.process;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.openapi.smeonboarding.process.start.SmallBusinessOnboardingProcessStartResponse;
import cz.moneta.test.dsl.openapi.smeonboarding.SmallBusinessOnboardingEndpointsConstants;
import cz.moneta.test.harness.support.rest.RawRestRequest;

public class SmallBusinessOnboardingProcessUtils {

    private static final String PROXY_AUTHORIZATION_START_TOKEN_CONFIG = "smeonboarding.start.token";

    public static RawRestRequest.Post createStartProcessUnsecuredRequest(Harness harness) {
        String startToken = harness.getConfig(PROXY_AUTHORIZATION_START_TOKEN_CONFIG);

        return harness.withOpenApi()
                .prepareUnsecuredRequest()
                .withPath(SmallBusinessOnboardingEndpointsConstants.PROCESS_START_ENDPOINT)
                .withHeader("Proxy-Authorization", startToken)
                .withHeader("Content-Type", "application/json")
                .withPayload("{}");
    }

    public static String startProcessAndGetToken(Harness harness) {
        return createStartProcessUnsecuredRequest(harness).post()
                .mapResponseIntoObject(SmallBusinessOnboardingProcessStartResponse.class)
                .getResponseObject()
                .getToken();
    }
}
