package cz.moneta.test.harness.connectors.rest;

import cz.moneta.test.harness.performance.PerformanceAware;
import org.apache.commons.lang3.tuple.Pair;

import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.function.Function;

public interface RestConnector extends PerformanceAware {
    <T> Pair<Integer, T> get(String path, Map<String, Object> properties, GenericType<T> responseType, Map<String, Object> headers);

    <T> Pair<Integer, T> post(String path, Entity<?> request, GenericType<T> responseType, Map<String, Object> headers);

    <T> Pair<Integer, T> delete(String path, Map<String, Object> properties, GenericType<T> responseType, Map<String, Object> headers);

    <T> Pair<Integer, T> patch(String path, Entity<?> request, GenericType<T> repsonseType, Map<String, Object> headers);

    RestConnector registerResponseHandler(
            ResponseHandler<Pair<Invocation.Builder, Function<Invocation.Builder, Response>>, Response> responseHandler);

    /**
     * Return response body with response headers.
     */
    default <T> Pair<Integer, ExtendedRestResponse<T>> postExtended(
            String path, Entity<?> request,
            Class<T> responseType, Map<String,
            Object> headers) {
        throw new IllegalStateException("Not implemented");
    }

    @Override
    default String getPerformanceReportKey(Object proxy, Method method, Object[] args) {
        return (String) args[0];
    }
}
