package cz.moneta.test.dsl.wso2;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.endpoints.wso2.Wso2GatewayEndpoint;
import cz.moneta.test.harness.support.mwf.MwfRequest;
import cz.moneta.test.harness.support.mwf.TifClient;
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 Wso2 {

    private final Harness harness;

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

    public RawRestRequest.Path prepareRequest() {
        Wso2GatewayEndpoint endpoint = harness.getEndpoint(Wso2GatewayEndpoint.class);
//                .registerResponseHandler(new TokenRenewalResponseHandler(() -> harness.tasks().wso2().authorization().ufoToken()));

        return RawRestRequest.jsonBuilder(endpoint);
    }

    public RawRestRequest.Path prepareRequest(long readTimeout) {
        Wso2GatewayEndpoint endpoint = harness.getEndpoint(Wso2GatewayEndpoint.class, readTimeout);
        return RawRestRequest.jsonBuilder(endpoint);
    }

    public RawRestRequest.Path prepareRequestXml() {
        return RawRestRequest.xmlBuilder(harness.getEndpoint(Wso2GatewayEndpoint.class));
    }

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

    @Deprecated
    // Tif should not be used
    public <RESP, R extends MwfRequest<R, RESP>> R prepareTifRequestAsCbl(Class<R> mwf) {
        return cz.moneta.test.harness.support.mwf.Builders.newMwfBuilder(mwf, TifClient.WSO2_CBL, harness);
    }

    @Deprecated
    // Tif should not be used
    public <RESP, R extends MwfRequest<R, RESP>> R prepareTifRequestAsUfo(Class<R> mwf) {
        return cz.moneta.test.harness.support.mwf.Builders.newMwfBuilder(mwf, TifClient.WSO2_UFO, harness);
    }

    @Deprecated
    // Tif should not be used
    public <RESP, R extends MwfRequest<R, RESP>> R prepareTifRequestAsGem(Class<R> mwf) {
        return cz.moneta.test.harness.support.mwf.Builders.newMwfBuilder(mwf, TifClient.WSO2_GEM, harness);
    }
}