/*
 * Daytona
 * Daytona AI platform API Docs
 *
 * The version of the OpenAPI document: 1.0
 * Contact: support@daytona.com
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package io.daytona.api.client.api;

import io.daytona.api.client.ApiCallback;
import io.daytona.api.client.ApiClient;
import io.daytona.api.client.ApiException;
import io.daytona.api.client.ApiResponse;
import io.daytona.api.client.Configuration;
import io.daytona.api.client.Pair;
import io.daytona.api.client.ProgressRequestBody;
import io.daytona.api.client.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import io.daytona.api.client.model.WebhookAppPortalAccess;
import io.daytona.api.client.model.WebhookInitializationStatus;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WebhooksApi {
    private ApiClient localVarApiClient;
    private int localHostIndex;
    private String localCustomBaseUrl;

    public WebhooksApi() {
        this(Configuration.getDefaultApiClient());
    }

    public WebhooksApi(ApiClient apiClient) {
        this.localVarApiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return localVarApiClient;
    }

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

    public int getHostIndex() {
        return localHostIndex;
    }

    public void setHostIndex(int hostIndex) {
        this.localHostIndex = hostIndex;
    }

    public String getCustomBaseUrl() {
        return localCustomBaseUrl;
    }

    public void setCustomBaseUrl(String customBaseUrl) {
        this.localCustomBaseUrl = customBaseUrl;
    }

    /**
     * Build call for webhookControllerGetAppPortalAccess
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @param _callback Callback for upload/download progress
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> App Portal access generated successfully </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call webhookControllerGetAppPortalAccessCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback _callback) throws ApiException {
        String basePath = null;
        // Operation Servers
        String[] localBasePaths = new String[] {  };

        // Determine Base Path to Use
        if (localCustomBaseUrl != null){
            basePath = localCustomBaseUrl;
        } else if ( localBasePaths.length > 0 ) {
            basePath = localBasePaths[localHostIndex];
        } else {
            basePath = null;
        }

        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/webhooks/organizations/{organizationId}/app-portal-access"
            .replace("{" + "organizationId" + "}", localVarApiClient.escapeString(organizationId.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        Map<String, String> localVarCookieParams = new HashMap<String, String>();
        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) {
            localVarHeaderParams.put("Accept", localVarAccept);
        }

        final String[] localVarContentTypes = {
        };
        final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
        if (localVarContentType != null) {
            localVarHeaderParams.put("Content-Type", localVarContentType);
        }

        if (xDaytonaOrganizationID != null) {
            localVarHeaderParams.put("X-Daytona-Organization-ID", localVarApiClient.parameterToString(xDaytonaOrganizationID));
        }


        String[] localVarAuthNames = new String[] { "bearer", "oauth2" };
        return localVarApiClient.buildCall(basePath, localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call webhookControllerGetAppPortalAccessValidateBeforeCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'organizationId' is set
        if (organizationId == null) {
            throw new ApiException("Missing the required parameter 'organizationId' when calling webhookControllerGetAppPortalAccess(Async)");
        }

        return webhookControllerGetAppPortalAccessCall(organizationId, xDaytonaOrganizationID, _callback);

    }

    /**
     * Get Svix Consumer App Portal access for an organization
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @return WebhookAppPortalAccess
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> App Portal access generated successfully </td><td>  -  </td></tr>
     </table>
     */
    public WebhookAppPortalAccess webhookControllerGetAppPortalAccess(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID) throws ApiException {
        ApiResponse<WebhookAppPortalAccess> localVarResp = webhookControllerGetAppPortalAccessWithHttpInfo(organizationId, xDaytonaOrganizationID);
        return localVarResp.getData();
    }

    /**
     * Get Svix Consumer App Portal access for an organization
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @return ApiResponse&lt;WebhookAppPortalAccess&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> App Portal access generated successfully </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<WebhookAppPortalAccess> webhookControllerGetAppPortalAccessWithHttpInfo(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID) throws ApiException {
        okhttp3.Call localVarCall = webhookControllerGetAppPortalAccessValidateBeforeCall(organizationId, xDaytonaOrganizationID, null);
        Type localVarReturnType = new TypeToken<WebhookAppPortalAccess>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Get Svix Consumer App Portal access for an organization (asynchronously)
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @param _callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> App Portal access generated successfully </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call webhookControllerGetAppPortalAccessAsync(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback<WebhookAppPortalAccess> _callback) throws ApiException {

        okhttp3.Call localVarCall = webhookControllerGetAppPortalAccessValidateBeforeCall(organizationId, xDaytonaOrganizationID, _callback);
        Type localVarReturnType = new TypeToken<WebhookAppPortalAccess>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
    /**
     * Build call for webhookControllerGetInitializationStatus
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @param _callback Callback for upload/download progress
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Webhook initialization status </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call webhookControllerGetInitializationStatusCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback _callback) throws ApiException {
        String basePath = null;
        // Operation Servers
        String[] localBasePaths = new String[] {  };

        // Determine Base Path to Use
        if (localCustomBaseUrl != null){
            basePath = localCustomBaseUrl;
        } else if ( localBasePaths.length > 0 ) {
            basePath = localBasePaths[localHostIndex];
        } else {
            basePath = null;
        }

        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/webhooks/organizations/{organizationId}/initialization-status"
            .replace("{" + "organizationId" + "}", localVarApiClient.escapeString(organizationId.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        Map<String, String> localVarCookieParams = new HashMap<String, String>();
        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) {
            localVarHeaderParams.put("Accept", localVarAccept);
        }

        final String[] localVarContentTypes = {
        };
        final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
        if (localVarContentType != null) {
            localVarHeaderParams.put("Content-Type", localVarContentType);
        }

        if (xDaytonaOrganizationID != null) {
            localVarHeaderParams.put("X-Daytona-Organization-ID", localVarApiClient.parameterToString(xDaytonaOrganizationID));
        }


        String[] localVarAuthNames = new String[] { "bearer", "oauth2" };
        return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call webhookControllerGetInitializationStatusValidateBeforeCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'organizationId' is set
        if (organizationId == null) {
            throw new ApiException("Missing the required parameter 'organizationId' when calling webhookControllerGetInitializationStatus(Async)");
        }

        return webhookControllerGetInitializationStatusCall(organizationId, xDaytonaOrganizationID, _callback);

    }

    /**
     * Get webhook initialization status for an organization
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @return WebhookInitializationStatus
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Webhook initialization status </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public WebhookInitializationStatus webhookControllerGetInitializationStatus(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID) throws ApiException {
        ApiResponse<WebhookInitializationStatus> localVarResp = webhookControllerGetInitializationStatusWithHttpInfo(organizationId, xDaytonaOrganizationID);
        return localVarResp.getData();
    }

    /**
     * Get webhook initialization status for an organization
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @return ApiResponse&lt;WebhookInitializationStatus&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Webhook initialization status </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<WebhookInitializationStatus> webhookControllerGetInitializationStatusWithHttpInfo(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID) throws ApiException {
        okhttp3.Call localVarCall = webhookControllerGetInitializationStatusValidateBeforeCall(organizationId, xDaytonaOrganizationID, null);
        Type localVarReturnType = new TypeToken<WebhookInitializationStatus>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Get webhook initialization status for an organization (asynchronously)
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @param _callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Webhook initialization status </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call webhookControllerGetInitializationStatusAsync(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback<WebhookInitializationStatus> _callback) throws ApiException {

        okhttp3.Call localVarCall = webhookControllerGetInitializationStatusValidateBeforeCall(organizationId, xDaytonaOrganizationID, _callback);
        Type localVarReturnType = new TypeToken<WebhookInitializationStatus>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
    /**
     * Build call for webhookControllerRefreshEndpoints
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @param _callback Callback for upload/download progress
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 204 </td><td> Endpoint flag refreshed </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call webhookControllerRefreshEndpointsCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback _callback) throws ApiException {
        String basePath = null;
        // Operation Servers
        String[] localBasePaths = new String[] {  };

        // Determine Base Path to Use
        if (localCustomBaseUrl != null){
            basePath = localCustomBaseUrl;
        } else if ( localBasePaths.length > 0 ) {
            basePath = localBasePaths[localHostIndex];
        } else {
            basePath = null;
        }

        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/webhooks/organizations/{organizationId}/refresh-endpoints"
            .replace("{" + "organizationId" + "}", localVarApiClient.escapeString(organizationId.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        Map<String, String> localVarCookieParams = new HashMap<String, String>();
        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
        };
        final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) {
            localVarHeaderParams.put("Accept", localVarAccept);
        }

        final String[] localVarContentTypes = {
        };
        final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
        if (localVarContentType != null) {
            localVarHeaderParams.put("Content-Type", localVarContentType);
        }

        if (xDaytonaOrganizationID != null) {
            localVarHeaderParams.put("X-Daytona-Organization-ID", localVarApiClient.parameterToString(xDaytonaOrganizationID));
        }


        String[] localVarAuthNames = new String[] { "bearer", "oauth2" };
        return localVarApiClient.buildCall(basePath, localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call webhookControllerRefreshEndpointsValidateBeforeCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'organizationId' is set
        if (organizationId == null) {
            throw new ApiException("Missing the required parameter 'organizationId' when calling webhookControllerRefreshEndpoints(Async)");
        }

        return webhookControllerRefreshEndpointsCall(organizationId, xDaytonaOrganizationID, _callback);

    }

    /**
     * Refresh cached endpoint presence flag for an organization
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 204 </td><td> Endpoint flag refreshed </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public void webhookControllerRefreshEndpoints(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID) throws ApiException {
        webhookControllerRefreshEndpointsWithHttpInfo(organizationId, xDaytonaOrganizationID);
    }

    /**
     * Refresh cached endpoint presence flag for an organization
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @return ApiResponse&lt;Void&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 204 </td><td> Endpoint flag refreshed </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<Void> webhookControllerRefreshEndpointsWithHttpInfo(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID) throws ApiException {
        okhttp3.Call localVarCall = webhookControllerRefreshEndpointsValidateBeforeCall(organizationId, xDaytonaOrganizationID, null);
        return localVarApiClient.execute(localVarCall);
    }

    /**
     * Refresh cached endpoint presence flag for an organization (asynchronously)
     * 
     * @param organizationId  (required)
     * @param xDaytonaOrganizationID Use with JWT to specify the organization ID (optional)
     * @param _callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 204 </td><td> Endpoint flag refreshed </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> Webhook initialization status not found </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call webhookControllerRefreshEndpointsAsync(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable String xDaytonaOrganizationID, final ApiCallback<Void> _callback) throws ApiException {

        okhttp3.Call localVarCall = webhookControllerRefreshEndpointsValidateBeforeCall(organizationId, xDaytonaOrganizationID, _callback);
        localVarApiClient.executeAsync(localVarCall, _callback);
        return localVarCall;
    }
}
