/*
 * Ory APIs
 * Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers. 
 *
 * The version of the OpenAPI document: v1.1.51
 * Contact: support@ory.sh
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package sh.ory.api;

import sh.ory.ApiCallback;
import sh.ory.ApiClient;
import sh.ory.ApiException;
import sh.ory.ApiResponse;
import sh.ory.Configuration;
import sh.ory.Pair;
import sh.ory.ProgressRequestBody;
import sh.ory.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import sh.ory.model.CheckPermissionResult;
import sh.ory.model.ErrorGeneric;
import sh.ory.model.ExpandedPermissionTree;
import sh.ory.model.PostCheckPermissionBody;
import sh.ory.model.PostCheckPermissionOrErrorBody;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;

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

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

    public PermissionApi(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 checkPermission
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call checkPermissionCall(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth, 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 = "/relation-tuples/check/openapi";

        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 (namespace != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("namespace", namespace));
        }

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

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

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

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

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

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

        if (maxDepth != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("max-depth", maxDepth));
        }

        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[] { "oryAccessToken" };
        return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call checkPermissionValidateBeforeCall(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth, final ApiCallback _callback) throws ApiException {
        return checkPermissionCall(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth, _callback);

    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (optional)
     * @return CheckPermissionResult
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public CheckPermissionResult checkPermission(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth) throws ApiException {
        ApiResponse<CheckPermissionResult> localVarResp = checkPermissionWithHttpInfo(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth);
        return localVarResp.getData();
    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (optional)
     * @return ApiResponse&lt;CheckPermissionResult&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<CheckPermissionResult> checkPermissionWithHttpInfo(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth) throws ApiException {
        okhttp3.Call localVarCall = checkPermissionValidateBeforeCall(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth, null);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Check a permission (asynchronously)
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call checkPermissionAsync(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth, final ApiCallback<CheckPermissionResult> _callback) throws ApiException {

        okhttp3.Call localVarCall = checkPermissionValidateBeforeCall(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth, _callback);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
    /**
     * Build call for checkPermissionOrError
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call checkPermissionOrErrorCall(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth, 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 = "/relation-tuples/check";

        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 (namespace != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("namespace", namespace));
        }

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

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

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

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

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

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

        if (maxDepth != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("max-depth", maxDepth));
        }

        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[] { "oryAccessToken" };
        return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call checkPermissionOrErrorValidateBeforeCall(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth, final ApiCallback _callback) throws ApiException {
        return checkPermissionOrErrorCall(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth, _callback);

    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (optional)
     * @return CheckPermissionResult
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public CheckPermissionResult checkPermissionOrError(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth) throws ApiException {
        ApiResponse<CheckPermissionResult> localVarResp = checkPermissionOrErrorWithHttpInfo(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth);
        return localVarResp.getData();
    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (optional)
     * @return ApiResponse&lt;CheckPermissionResult&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<CheckPermissionResult> checkPermissionOrErrorWithHttpInfo(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth) throws ApiException {
        okhttp3.Call localVarCall = checkPermissionOrErrorValidateBeforeCall(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth, null);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Check a permission (asynchronously)
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param namespace Namespace of the Relationship (optional)
     * @param _object Object of the Relationship (optional)
     * @param relation Relation of the Relationship (optional)
     * @param subjectId SubjectID of the Relationship (optional)
     * @param subjectSetNamespace Namespace of the Subject Set (optional)
     * @param subjectSetObject Object of the Subject Set (optional)
     * @param subjectSetRelation Relation of the Subject Set (optional)
     * @param maxDepth  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call checkPermissionOrErrorAsync(String namespace, String _object, String relation, String subjectId, String subjectSetNamespace, String subjectSetObject, String subjectSetRelation, Long maxDepth, final ApiCallback<CheckPermissionResult> _callback) throws ApiException {

        okhttp3.Call localVarCall = checkPermissionOrErrorValidateBeforeCall(namespace, _object, relation, subjectId, subjectSetNamespace, subjectSetObject, subjectSetRelation, maxDepth, _callback);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
    /**
     * Build call for expandPermissions
     * @param namespace Namespace of the Subject Set (required)
     * @param _object Object of the Subject Set (required)
     * @param relation Relation of the Subject Set (required)
     * @param maxDepth  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> expandedPermissionTree </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call expandPermissionsCall(String namespace, String _object, String relation, Long maxDepth, 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 = "/relation-tuples/expand";

        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 (namespace != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("namespace", namespace));
        }

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

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

        if (maxDepth != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("max-depth", maxDepth));
        }

        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[] { "oryAccessToken" };
        return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call expandPermissionsValidateBeforeCall(String namespace, String _object, String relation, Long maxDepth, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'namespace' is set
        if (namespace == null) {
            throw new ApiException("Missing the required parameter 'namespace' when calling expandPermissions(Async)");
        }

        // verify the required parameter '_object' is set
        if (_object == null) {
            throw new ApiException("Missing the required parameter '_object' when calling expandPermissions(Async)");
        }

        // verify the required parameter 'relation' is set
        if (relation == null) {
            throw new ApiException("Missing the required parameter 'relation' when calling expandPermissions(Async)");
        }

        return expandPermissionsCall(namespace, _object, relation, maxDepth, _callback);

    }

    /**
     * Expand a Relationship into permissions.
     * Use this endpoint to expand a relationship tuple into permissions.
     * @param namespace Namespace of the Subject Set (required)
     * @param _object Object of the Subject Set (required)
     * @param relation Relation of the Subject Set (required)
     * @param maxDepth  (optional)
     * @return ExpandedPermissionTree
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> expandedPermissionTree </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public ExpandedPermissionTree expandPermissions(String namespace, String _object, String relation, Long maxDepth) throws ApiException {
        ApiResponse<ExpandedPermissionTree> localVarResp = expandPermissionsWithHttpInfo(namespace, _object, relation, maxDepth);
        return localVarResp.getData();
    }

    /**
     * Expand a Relationship into permissions.
     * Use this endpoint to expand a relationship tuple into permissions.
     * @param namespace Namespace of the Subject Set (required)
     * @param _object Object of the Subject Set (required)
     * @param relation Relation of the Subject Set (required)
     * @param maxDepth  (optional)
     * @return ApiResponse&lt;ExpandedPermissionTree&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> expandedPermissionTree </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<ExpandedPermissionTree> expandPermissionsWithHttpInfo(String namespace, String _object, String relation, Long maxDepth) throws ApiException {
        okhttp3.Call localVarCall = expandPermissionsValidateBeforeCall(namespace, _object, relation, maxDepth, null);
        Type localVarReturnType = new TypeToken<ExpandedPermissionTree>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Expand a Relationship into permissions. (asynchronously)
     * Use this endpoint to expand a relationship tuple into permissions.
     * @param namespace Namespace of the Subject Set (required)
     * @param _object Object of the Subject Set (required)
     * @param relation Relation of the Subject Set (required)
     * @param maxDepth  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> expandedPermissionTree </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 404 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call expandPermissionsAsync(String namespace, String _object, String relation, Long maxDepth, final ApiCallback<ExpandedPermissionTree> _callback) throws ApiException {

        okhttp3.Call localVarCall = expandPermissionsValidateBeforeCall(namespace, _object, relation, maxDepth, _callback);
        Type localVarReturnType = new TypeToken<ExpandedPermissionTree>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
    /**
     * Build call for postCheckPermission
     * @param maxDepth  (optional)
     * @param postCheckPermissionBody  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call postCheckPermissionCall(Long maxDepth, PostCheckPermissionBody postCheckPermissionBody, 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 = postCheckPermissionBody;

        // create path and map variables
        String localVarPath = "/relation-tuples/check/openapi";

        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 (maxDepth != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("max-depth", maxDepth));
        }

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

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

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

    @SuppressWarnings("rawtypes")
    private okhttp3.Call postCheckPermissionValidateBeforeCall(Long maxDepth, PostCheckPermissionBody postCheckPermissionBody, final ApiCallback _callback) throws ApiException {
        return postCheckPermissionCall(maxDepth, postCheckPermissionBody, _callback);

    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param maxDepth  (optional)
     * @param postCheckPermissionBody  (optional)
     * @return CheckPermissionResult
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public CheckPermissionResult postCheckPermission(Long maxDepth, PostCheckPermissionBody postCheckPermissionBody) throws ApiException {
        ApiResponse<CheckPermissionResult> localVarResp = postCheckPermissionWithHttpInfo(maxDepth, postCheckPermissionBody);
        return localVarResp.getData();
    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param maxDepth  (optional)
     * @param postCheckPermissionBody  (optional)
     * @return ApiResponse&lt;CheckPermissionResult&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<CheckPermissionResult> postCheckPermissionWithHttpInfo(Long maxDepth, PostCheckPermissionBody postCheckPermissionBody) throws ApiException {
        okhttp3.Call localVarCall = postCheckPermissionValidateBeforeCall(maxDepth, postCheckPermissionBody, null);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Check a permission (asynchronously)
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param maxDepth  (optional)
     * @param postCheckPermissionBody  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call postCheckPermissionAsync(Long maxDepth, PostCheckPermissionBody postCheckPermissionBody, final ApiCallback<CheckPermissionResult> _callback) throws ApiException {

        okhttp3.Call localVarCall = postCheckPermissionValidateBeforeCall(maxDepth, postCheckPermissionBody, _callback);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
    /**
     * Build call for postCheckPermissionOrError
     * @param maxDepth nolint:deadcode,unused (optional)
     * @param postCheckPermissionOrErrorBody  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call postCheckPermissionOrErrorCall(Long maxDepth, PostCheckPermissionOrErrorBody postCheckPermissionOrErrorBody, 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 = postCheckPermissionOrErrorBody;

        // create path and map variables
        String localVarPath = "/relation-tuples/check";

        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 (maxDepth != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("max-depth", maxDepth));
        }

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

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

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

    @SuppressWarnings("rawtypes")
    private okhttp3.Call postCheckPermissionOrErrorValidateBeforeCall(Long maxDepth, PostCheckPermissionOrErrorBody postCheckPermissionOrErrorBody, final ApiCallback _callback) throws ApiException {
        return postCheckPermissionOrErrorCall(maxDepth, postCheckPermissionOrErrorBody, _callback);

    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param maxDepth nolint:deadcode,unused (optional)
     * @param postCheckPermissionOrErrorBody  (optional)
     * @return CheckPermissionResult
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public CheckPermissionResult postCheckPermissionOrError(Long maxDepth, PostCheckPermissionOrErrorBody postCheckPermissionOrErrorBody) throws ApiException {
        ApiResponse<CheckPermissionResult> localVarResp = postCheckPermissionOrErrorWithHttpInfo(maxDepth, postCheckPermissionOrErrorBody);
        return localVarResp.getData();
    }

    /**
     * Check a permission
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param maxDepth nolint:deadcode,unused (optional)
     * @param postCheckPermissionOrErrorBody  (optional)
     * @return ApiResponse&lt;CheckPermissionResult&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<CheckPermissionResult> postCheckPermissionOrErrorWithHttpInfo(Long maxDepth, PostCheckPermissionOrErrorBody postCheckPermissionOrErrorBody) throws ApiException {
        okhttp3.Call localVarCall = postCheckPermissionOrErrorValidateBeforeCall(maxDepth, postCheckPermissionOrErrorBody, null);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Check a permission (asynchronously)
     * To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
     * @param maxDepth nolint:deadcode,unused (optional)
     * @param postCheckPermissionOrErrorBody  (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 summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> errorGeneric </td><td>  -  </td></tr>
        <tr><td> 403 </td><td> checkPermissionResult </td><td>  -  </td></tr>
        <tr><td> 0 </td><td> errorGeneric </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call postCheckPermissionOrErrorAsync(Long maxDepth, PostCheckPermissionOrErrorBody postCheckPermissionOrErrorBody, final ApiCallback<CheckPermissionResult> _callback) throws ApiException {

        okhttp3.Call localVarCall = postCheckPermissionOrErrorValidateBeforeCall(maxDepth, postCheckPermissionOrErrorBody, _callback);
        Type localVarReturnType = new TypeToken<CheckPermissionResult>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
}
