/*
 * 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 java.math.BigDecimal;
import java.time.OffsetDateTime;
import io.daytona.api.client.model.PaginatedAuditLogs;

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

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

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

    public AuditApi(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 getOrganizationAuditLogs
     * @param organizationId Organization ID (required)
     * @param page Page number of the results (optional, default to 1)
     * @param limit Number of results per page (optional, default to 100)
     * @param from From date (ISO 8601 format) (optional)
     * @param to To date (ISO 8601 format) (optional)
     * @param nextToken Token for cursor-based pagination. When provided, takes precedence over page parameter. (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> Paginated list of organization audit logs </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call getOrganizationAuditLogsCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable BigDecimal page, @javax.annotation.Nullable BigDecimal limit, @javax.annotation.Nullable OffsetDateTime from, @javax.annotation.Nullable OffsetDateTime to, @javax.annotation.Nullable String nextToken, 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 = "/audit/organizations/{organizationId}"
            .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>();

        if (page != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("page", page));
        }

        if (limit != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("limit", limit));
        }

        if (from != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("from", from));
        }

        if (to != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("to", to));
        }

        if (nextToken != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("nextToken", nextToken));
        }

        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);
        }

        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 getOrganizationAuditLogsValidateBeforeCall(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable BigDecimal page, @javax.annotation.Nullable BigDecimal limit, @javax.annotation.Nullable OffsetDateTime from, @javax.annotation.Nullable OffsetDateTime to, @javax.annotation.Nullable String nextToken, 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 getOrganizationAuditLogs(Async)");
        }

        return getOrganizationAuditLogsCall(organizationId, page, limit, from, to, nextToken, _callback);

    }

    /**
     * Get audit logs for organization
     * 
     * @param organizationId Organization ID (required)
     * @param page Page number of the results (optional, default to 1)
     * @param limit Number of results per page (optional, default to 100)
     * @param from From date (ISO 8601 format) (optional)
     * @param to To date (ISO 8601 format) (optional)
     * @param nextToken Token for cursor-based pagination. When provided, takes precedence over page parameter. (optional)
     * @return PaginatedAuditLogs
     * @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> Paginated list of organization audit logs </td><td>  -  </td></tr>
     </table>
     */
    public PaginatedAuditLogs getOrganizationAuditLogs(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable BigDecimal page, @javax.annotation.Nullable BigDecimal limit, @javax.annotation.Nullable OffsetDateTime from, @javax.annotation.Nullable OffsetDateTime to, @javax.annotation.Nullable String nextToken) throws ApiException {
        ApiResponse<PaginatedAuditLogs> localVarResp = getOrganizationAuditLogsWithHttpInfo(organizationId, page, limit, from, to, nextToken);
        return localVarResp.getData();
    }

    /**
     * Get audit logs for organization
     * 
     * @param organizationId Organization ID (required)
     * @param page Page number of the results (optional, default to 1)
     * @param limit Number of results per page (optional, default to 100)
     * @param from From date (ISO 8601 format) (optional)
     * @param to To date (ISO 8601 format) (optional)
     * @param nextToken Token for cursor-based pagination. When provided, takes precedence over page parameter. (optional)
     * @return ApiResponse&lt;PaginatedAuditLogs&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> Paginated list of organization audit logs </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<PaginatedAuditLogs> getOrganizationAuditLogsWithHttpInfo(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable BigDecimal page, @javax.annotation.Nullable BigDecimal limit, @javax.annotation.Nullable OffsetDateTime from, @javax.annotation.Nullable OffsetDateTime to, @javax.annotation.Nullable String nextToken) throws ApiException {
        okhttp3.Call localVarCall = getOrganizationAuditLogsValidateBeforeCall(organizationId, page, limit, from, to, nextToken, null);
        Type localVarReturnType = new TypeToken<PaginatedAuditLogs>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Get audit logs for organization (asynchronously)
     * 
     * @param organizationId Organization ID (required)
     * @param page Page number of the results (optional, default to 1)
     * @param limit Number of results per page (optional, default to 100)
     * @param from From date (ISO 8601 format) (optional)
     * @param to To date (ISO 8601 format) (optional)
     * @param nextToken Token for cursor-based pagination. When provided, takes precedence over page parameter. (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> Paginated list of organization audit logs </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call getOrganizationAuditLogsAsync(@javax.annotation.Nonnull String organizationId, @javax.annotation.Nullable BigDecimal page, @javax.annotation.Nullable BigDecimal limit, @javax.annotation.Nullable OffsetDateTime from, @javax.annotation.Nullable OffsetDateTime to, @javax.annotation.Nullable String nextToken, final ApiCallback<PaginatedAuditLogs> _callback) throws ApiException {

        okhttp3.Call localVarCall = getOrganizationAuditLogsValidateBeforeCall(organizationId, page, limit, from, to, nextToken, _callback);
        Type localVarReturnType = new TypeToken<PaginatedAuditLogs>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
}
