package com.eactive.httpmockserver.client.controller;

import com.eactive.httpmockserver.client.dto.ApiRequestDTO;
import com.eactive.httpmockserver.client.dto.ApiResponse;
import com.eactive.httpmockserver.client.service.NettyApiClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.ExecutionException;

@RestController
public class ApiClientController {

    private final NettyApiClient nettyApiClient;

    public ApiClientController(NettyApiClient nettyApiClient) {
        this.nettyApiClient = nettyApiClient;
    }

    @PostMapping("/mgmt/api/test.do")
    public ApiResponse handleApiRequest(@RequestBody ApiRequestDTO request) throws InterruptedException, ExecutionException, InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {

        return nettyApiClient.handleRequest(request).get();
    }
}
