package cz.moneta.test.dsl.caapi;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.endpoints.openapica.OpenApiCaEndpoint;
import cz.moneta.test.harness.support.rest.Builders;
import cz.moneta.test.harness.support.rest.RawRestRequest;
import cz.moneta.test.harness.support.rest.RestRequest;

public class CaApiBuilder {

    private Harness harness;

    public CaApiBuilder(Harness harness) {
        this.harness = harness;
    }

    public RawRestRequest.Path prepareRequest() {
        return RawRestRequest.jsonBuilder(harness.getEndpoint(OpenApiCaEndpoint.class));
    }

    public RawRestRequest.Path prepareSecuredRequest() {
        return prepareRequestPathPrefix("secured/");
    }

    public RawRestRequest.Path prepareUnsecuredRequest() {
        return prepareRequestPathPrefix("unsecured/");
    }

    private RawRestRequest.Path prepareRequestPathPrefix(String pathPrefix) {
        OpenApiCaEndpoint endpoint = harness.getEndpoint(OpenApiCaEndpoint.class);
        return RawRestRequest.jsonBuilder(endpoint)
                .setPathPrefix(pathPrefix);
    }

    private <RESP, B extends RestRequest<B, ?, RESP>> B getBuilder(Class<B> builderClass) {
        return Builders.newRestBuilder(builderClass, OpenApiCaEndpoint.class, harness);
    }
}
