package org.appng.openapi;

import org.appng.openapi.invoke.ApiClient;

import org.appng.openapi.model.Action;
import org.appng.openapi.model.Datasource;
import org.appng.openapi.model.ErrorModel;
import org.appng.openapi.model.Navigation;
import org.appng.openapi.model.PageDefinition;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-03-20T12:57:48.851+01:00[Europe/Berlin]")
@Component("org.appng.openapi.AppNgApi")
public class AppNgApi {
    private ApiClient apiClient;

    public AppNgApi() {
        this(new ApiClient());
    }

    @Autowired
    public AppNgApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * 
     * Returns an action. To be used for initially retrieving the action.
     * <p><b>200</b> - action response
     * <p><b>400</b> - action response, in case an recoverable error occurred
     * <p><b>0</b> - unexpected/unrecoverable error
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param eventId event-id of the action (required)
     * @param id The ID of the action. (required)
     * @param params Parameters (including sorting and filtering parameters) are passed as matrix style parameters. Note that names and values of these matrix parameters must be URL-Encoded (required)
     * @return Action
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public Action getAction(String site, String application, String eventId, String id, String params) throws RestClientException {
        return getActionWithHttpInfo(site, application, eventId, id, params).getBody();
    }

    /**
     * 
     * Returns an action. To be used for initially retrieving the action.
     * <p><b>200</b> - action response
     * <p><b>400</b> - action response, in case an recoverable error occurred
     * <p><b>0</b> - unexpected/unrecoverable error
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param eventId event-id of the action (required)
     * @param id The ID of the action. (required)
     * @param params Parameters (including sorting and filtering parameters) are passed as matrix style parameters. Note that names and values of these matrix parameters must be URL-Encoded (required)
     * @return ResponseEntity&lt;Action&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<Action> getActionWithHttpInfo(String site, String application, String eventId, String id, String params) throws RestClientException {
        Object postBody = null;
        
        // verify the required parameter 'site' is set
        if (site == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'site' when calling getAction");
        }
        
        // verify the required parameter 'application' is set
        if (application == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'application' when calling getAction");
        }
        
        // verify the required parameter 'eventId' is set
        if (eventId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'eventId' when calling getAction");
        }
        
        // verify the required parameter 'id' is set
        if (id == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'id' when calling getAction");
        }
        
        // verify the required parameter 'params' is set
        if (params == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'params' when calling getAction");
        }
        
        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("site", site);
        uriVariables.put("application", application);
        uriVariables.put("event-id", eventId);
        uriVariables.put("id", id);
        uriVariables.put("params", params);
        String path = apiClient.expandPath("/service/{site}/{application}/rest/openapi/action/{event-id}/{id}/{params}", uriVariables);

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] localVarAccepts = { 
            "application/json"
         };
        final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        final String[] contentTypes = {  };
        final MediaType localVarContentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "appNGCookie" };

        ParameterizedTypeReference<Action> returnType = new ParameterizedTypeReference<Action>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, authNames, returnType);
    }
    /**
     * 
     * Returns a datasource by id
     * <p><b>200</b> - datasource response
     * <p><b>0</b> - unexpected error
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param id The id of the datasource. (required)
     * @param params The id of the datasource. Parameters (including sorting and filtering parameters) are passed as matrix style parameters. Note that names and values of these matrix parameters must be URL-Encoded  (required)
     * @return Datasource
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public Datasource getDatasource(String site, String application, String id, String params) throws RestClientException {
        return getDatasourceWithHttpInfo(site, application, id, params).getBody();
    }

    /**
     * 
     * Returns a datasource by id
     * <p><b>200</b> - datasource response
     * <p><b>0</b> - unexpected error
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param id The id of the datasource. (required)
     * @param params The id of the datasource. Parameters (including sorting and filtering parameters) are passed as matrix style parameters. Note that names and values of these matrix parameters must be URL-Encoded  (required)
     * @return ResponseEntity&lt;Datasource&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<Datasource> getDatasourceWithHttpInfo(String site, String application, String id, String params) throws RestClientException {
        Object postBody = null;
        
        // verify the required parameter 'site' is set
        if (site == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'site' when calling getDatasource");
        }
        
        // verify the required parameter 'application' is set
        if (application == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'application' when calling getDatasource");
        }
        
        // verify the required parameter 'id' is set
        if (id == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'id' when calling getDatasource");
        }
        
        // verify the required parameter 'params' is set
        if (params == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'params' when calling getDatasource");
        }
        
        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("site", site);
        uriVariables.put("application", application);
        uriVariables.put("id", id);
        uriVariables.put("params", params);
        String path = apiClient.expandPath("/service/{site}/{application}/rest/openapi/datasource/{id}/{params}", uriVariables);

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] localVarAccepts = { 
            "application/json"
         };
        final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        final String[] contentTypes = {  };
        final MediaType localVarContentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "appNGCookie" };

        ParameterizedTypeReference<Datasource> returnType = new ParameterizedTypeReference<Datasource>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, authNames, returnType);
    }
    /**
     * 
     * 
     * <p><b>200</b> - datasource response
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @return Navigation
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public Navigation getNavigation(String site, String application) throws RestClientException {
        return getNavigationWithHttpInfo(site, application).getBody();
    }

    /**
     * 
     * 
     * <p><b>200</b> - datasource response
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @return ResponseEntity&lt;Navigation&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<Navigation> getNavigationWithHttpInfo(String site, String application) throws RestClientException {
        Object postBody = null;
        
        // verify the required parameter 'site' is set
        if (site == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'site' when calling getNavigation");
        }
        
        // verify the required parameter 'application' is set
        if (application == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'application' when calling getNavigation");
        }
        
        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("site", site);
        uriVariables.put("application", application);
        String path = apiClient.expandPath("/service/{site}/{application}/rest/openapi/navigation", uriVariables);

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] localVarAccepts = { 
            "application/json"
         };
        final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        final String[] contentTypes = {  };
        final MediaType localVarContentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "appNGCookie" };

        ParameterizedTypeReference<Navigation> returnType = new ParameterizedTypeReference<Navigation>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, authNames, returnType);
    }
    /**
     * 
     * 
     * <p><b>200</b> - datasource response
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param id the ID of the page (required)
     * @param pageUrlParams the URL path to parametrize the page with. (required)
     * @param sect a list of section IDs to fill (optional)
     * @return PageDefinition
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public PageDefinition getPageWithUrlParams(String site, String application, String id, String pageUrlParams, List<String> sect) throws RestClientException {
        return getPageWithUrlParamsWithHttpInfo(site, application, id, pageUrlParams, sect).getBody();
    }

    /**
     * 
     * 
     * <p><b>200</b> - datasource response
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param id the ID of the page (required)
     * @param pageUrlParams the URL path to parametrize the page with. (required)
     * @param sect a list of section IDs to fill (optional)
     * @return ResponseEntity&lt;PageDefinition&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<PageDefinition> getPageWithUrlParamsWithHttpInfo(String site, String application, String id, String pageUrlParams, List<String> sect) throws RestClientException {
        Object postBody = null;
        
        // verify the required parameter 'site' is set
        if (site == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'site' when calling getPageWithUrlParams");
        }
        
        // verify the required parameter 'application' is set
        if (application == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'application' when calling getPageWithUrlParams");
        }
        
        // verify the required parameter 'id' is set
        if (id == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'id' when calling getPageWithUrlParams");
        }
        
        // verify the required parameter 'pageUrlParams' is set
        if (pageUrlParams == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'pageUrlParams' when calling getPageWithUrlParams");
        }
        
        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("site", site);
        uriVariables.put("application", application);
        uriVariables.put("id", id);
        uriVariables.put("pageUrlParams", pageUrlParams);
        String path = apiClient.expandPath("/service/{site}/{application}/rest/openapi/page/{id}/{pageUrlParams}", uriVariables);

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "_sect", sect));

        final String[] localVarAccepts = { 
            "application/json"
         };
        final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        final String[] contentTypes = {  };
        final MediaType localVarContentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "appNGCookie" };

        ParameterizedTypeReference<PageDefinition> returnType = new ParameterizedTypeReference<PageDefinition>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, authNames, returnType);
    }
    /**
     * 
     * Performs an action.
     * <p><b>200</b> - action response
     * <p><b>400</b> - action response, in case an recoverable error occurred
     * <p><b>0</b> - unexpected/unrecoverable error
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param eventId event-id of the action (required)
     * @param id The ID of the action. (required)
     * @param params Parameters (including sorting and filtering parameters) are passed as matrix style parameters. Note that names and values of these matrix parameters must be URL-Encoded (required)
     * @return Action
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public Action performActionMultiPart(String site, String application, String eventId, String id, String params) throws RestClientException {
        return performActionMultiPartWithHttpInfo(site, application, eventId, id, params).getBody();
    }

    /**
     * 
     * Performs an action.
     * <p><b>200</b> - action response
     * <p><b>400</b> - action response, in case an recoverable error occurred
     * <p><b>0</b> - unexpected/unrecoverable error
     * @param site the site to call (required)
     * @param application the application to call (required)
     * @param eventId event-id of the action (required)
     * @param id The ID of the action. (required)
     * @param params Parameters (including sorting and filtering parameters) are passed as matrix style parameters. Note that names and values of these matrix parameters must be URL-Encoded (required)
     * @return ResponseEntity&lt;Action&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<Action> performActionMultiPartWithHttpInfo(String site, String application, String eventId, String id, String params) throws RestClientException {
        Object postBody = null;
        
        // verify the required parameter 'site' is set
        if (site == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'site' when calling performActionMultiPart");
        }
        
        // verify the required parameter 'application' is set
        if (application == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'application' when calling performActionMultiPart");
        }
        
        // verify the required parameter 'eventId' is set
        if (eventId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'eventId' when calling performActionMultiPart");
        }
        
        // verify the required parameter 'id' is set
        if (id == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'id' when calling performActionMultiPart");
        }
        
        // verify the required parameter 'params' is set
        if (params == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'params' when calling performActionMultiPart");
        }
        
        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("site", site);
        uriVariables.put("application", application);
        uriVariables.put("event-id", eventId);
        uriVariables.put("id", id);
        uriVariables.put("params", params);
        String path = apiClient.expandPath("/service/{site}/{application}/rest/openapi/action/multipart/{event-id}/{id}/{params}", uriVariables);

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] localVarAccepts = { 
            "application/json"
         };
        final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        final String[] contentTypes = { 
            "multipart/form-data"
         };
        final MediaType localVarContentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "appNGCookie" };

        ParameterizedTypeReference<Action> returnType = new ParameterizedTypeReference<Action>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, authNames, returnType);
    }
}
