/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import { apisCreateApi } from "../funcs/apisCreateApi.js";
import { apisDeleteApi } from "../funcs/apisDeleteApi.js";
import { apisGetApi } from "../funcs/apisGetApi.js";
import { apisListKeys } from "../funcs/apisListKeys.js";
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
import * as components from "../models/components/index.js";
import { unwrapAsync } from "../types/fp.js";

export class Apis extends ClientSDK {
  /**
   * Create API namespace
   *
   * @remarks
   * Create an API namespace for organizing keys by environment, service, or product.
   *
   * Use this to separate production from development keys, isolate different services, or manage multiple products. Each API gets a unique identifier and dedicated infrastructure for secure key operations.
   *
   * **Important**: API names must be unique within your workspace and cannot be changed after creation.
   *
   * **Required Permissions**
   *
   * Your root key must have one of the following permissions:
   * - `api.*.create_api` (to create APIs in any workspace)
   */
  async createApi(
    request: components.V2ApisCreateApiRequestBody,
    options?: RequestOptions,
  ): Promise<components.V2ApisCreateApiResponseBody> {
    return unwrapAsync(apisCreateApi(
      this,
      request,
      options,
    ));
  }

  /**
   * Delete API namespace
   *
   * @remarks
   * Permanently delete an API namespace and immediately invalidate all associated keys.
   *
   * Use this for cleaning up development environments, retiring deprecated services, or removing unused resources.
   * All keys in the namespace are immediately marked as deleted and will fail verification with `code=NOT_FOUND`.
   *
   * **Important**: This operation is immediate and permanent. Verify you have the correct API ID before deletion.
   * If delete protection is enabled, disable it first through the dashboard or API configuration.
   *
   * **Required Permissions**
   *
   * Your root key must have one of the following permissions:
   * - `api.*.delete_api` (to delete any API)
   * - `api.<api_id>.delete_api` (to delete a specific API)
   */
  async deleteApi(
    request: components.V2ApisDeleteApiRequestBody,
    options?: RequestOptions,
  ): Promise<components.V2ApisDeleteApiResponseBody> {
    return unwrapAsync(apisDeleteApi(
      this,
      request,
      options,
    ));
  }

  /**
   * Get API namespace
   *
   * @remarks
   * Retrieve basic information about an API namespace including its ID and name.
   *
   * Use this to verify an API exists before performing operations, get the human-readable name when you only have the API ID, or confirm access to a specific namespace. For detailed key information, use the `listKeys` endpoint instead.
   *
   * **Required Permissions**
   *
   * Your root key must have one of the following permissions:
   * - `api.*.read_api` (to read any API)
   * - `api.<api_id>.read_api` (to read a specific API)
   */
  async getApi(
    request: components.V2ApisGetApiRequestBody,
    options?: RequestOptions,
  ): Promise<components.V2ApisGetApiResponseBody> {
    return unwrapAsync(apisGetApi(
      this,
      request,
      options,
    ));
  }

  /**
   * List API keys
   *
   * @remarks
   * Retrieve a paginated list of API keys for dashboard and administrative interfaces.
   *
   * Use this to build key management dashboards, filter keys by user with `externalId`, or retrieve key details for administrative purposes. Each key includes status, metadata, permissions, and usage limits.
   *
   * **Important**: Set `decrypt: true` only in secure contexts to retrieve plaintext key values from recoverable keys.
   *
   * **Required Permissions**
   *
   * Your root key must have one of the following permissions for basic key listing:
   * - `api.*.read_key` (to read keys from any API)
   * - `api.<api_id>.read_key` (to read keys from a specific API)
   *
   * Additionally, you need read access to the API itself:
   * - `api.*.read_api` or `api.<api_id>.read_api`
   *
   * Additional permission required for decrypt functionality:
   * - `api.*.decrypt_key` or `api.<api_id>.decrypt_key`
   */
  async listKeys(
    request: components.V2ApisListKeysRequestBody,
    options?: RequestOptions,
  ): Promise<components.V2ApisListKeysResponseBody> {
    return unwrapAsync(apisListKeys(
      this,
      request,
      options,
    ));
  }
}
