// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../../core/resource';
import { APIPromise } from '../../../core/api-promise';
import { PagePromise, SinglePage } from '../../../core/pagination';
import { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';

export class BaseGatewayCA extends APIResource {
  static override readonly _key: readonly ['zeroTrust', 'access', 'gatewayCA'] = Object.freeze([
    'zeroTrust',
    'access',
    'gatewayCA',
  ] as const);

  /**
   * Adds a new SSH Certificate Authority (CA).
   *
   * @example
   * ```ts
   * const gatewayCA =
   *   await client.zeroTrust.access.gatewayCA.create({
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *   });
   * ```
   */
  create(params: GatewayCACreateParams, options?: RequestOptions): APIPromise<GatewayCACreateResponse> {
    const { account_id } = params;
    return (
      this._client.post(path`/accounts/${account_id}/access/gateway_ca`, options) as APIPromise<{
        result: GatewayCACreateResponse;
      }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Lists SSH Certificate Authorities (CA).
   *
   * @example
   * ```ts
   * // Automatically fetches more pages as needed.
   * for await (const gatewayCAListResponse of client.zeroTrust.access.gatewayCA.list(
   *   { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   * )) {
   *   // ...
   * }
   * ```
   */
  list(
    params: GatewayCAListParams,
    options?: RequestOptions,
  ): PagePromise<GatewayCAListResponsesSinglePage, GatewayCAListResponse> {
    const { account_id } = params;
    return this._client.getAPIList(
      path`/accounts/${account_id}/access/gateway_ca`,
      SinglePage<GatewayCAListResponse>,
      options,
    );
  }

  /**
   * Deletes an SSH Certificate Authority.
   *
   * @example
   * ```ts
   * const gatewayCA =
   *   await client.zeroTrust.access.gatewayCA.delete(
   *     'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  delete(
    certificateID: string,
    params: GatewayCADeleteParams,
    options?: RequestOptions,
  ): APIPromise<GatewayCADeleteResponse> {
    const { account_id } = params;
    return (
      this._client.delete(
        path`/accounts/${account_id}/access/gateway_ca/${certificateID}`,
        options,
      ) as APIPromise<{ result: GatewayCADeleteResponse }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class GatewayCA extends BaseGatewayCA {}

export type GatewayCAListResponsesSinglePage = SinglePage<GatewayCAListResponse>;

export interface GatewayCACreateResponse {
  /**
   * The key ID of this certificate.
   */
  id?: string;

  /**
   * The public key of this certificate.
   */
  public_key?: string;
}

export interface GatewayCAListResponse {
  /**
   * The key ID of this certificate.
   */
  id?: string;

  /**
   * The public key of this certificate.
   */
  public_key?: string;
}

export interface GatewayCADeleteResponse {
  /**
   * UUID.
   */
  id?: string;
}

export interface GatewayCACreateParams {
  /**
   * Identifier.
   */
  account_id: string;
}

export interface GatewayCAListParams {
  /**
   * Identifier.
   */
  account_id: string;
}

export interface GatewayCADeleteParams {
  /**
   * Identifier.
   */
  account_id: string;
}

export declare namespace GatewayCA {
  export {
    type GatewayCACreateResponse as GatewayCACreateResponse,
    type GatewayCAListResponse as GatewayCAListResponse,
    type GatewayCADeleteResponse as GatewayCADeleteResponse,
    type GatewayCAListResponsesSinglePage as GatewayCAListResponsesSinglePage,
    type GatewayCACreateParams as GatewayCACreateParams,
    type GatewayCAListParams as GatewayCAListParams,
    type GatewayCADeleteParams as GatewayCADeleteParams,
  };
}
