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

import { APIResource } from '../../../resource';
import * as Core from '../../../core';
import * as CredentialsAPI from './credentials';
import {
  CredentialCreateParams,
  CredentialCreateResponse,
  CredentialDeleteParams,
  CredentialDeleteResponse,
  CredentialEditParams,
  CredentialEditResponse,
  CredentialGetParams,
  CredentialGetResponse,
  CredentialListParams,
  CredentialListResponse,
  CredentialListResponsesV4PagePaginationArray,
  CredentialUpdateParams,
  CredentialUpdateResponse,
  Credentials,
} from './credentials';
import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../../pagination';

export class CredentialSets extends APIResource {
  credentials: CredentialsAPI.Credentials = new CredentialsAPI.Credentials(this._client);

  /**
   * Creates a new credential set.
   *
   * @example
   * ```ts
   * const credentialSet =
   *   await client.vulnerabilityScanner.credentialSets.create({
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     name: 'Production API credentials',
   *   });
   * ```
   */
  create(
    params: CredentialSetCreateParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<CredentialSetCreateResponse> {
    const { account_id, ...body } = params;
    return (
      this._client.post(`/accounts/${account_id}/vuln_scanner/credential_sets`, {
        body,
        ...options,
      }) as Core.APIPromise<{ result: CredentialSetCreateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Replaces a credential set. All fields must be provided.
   *
   * @example
   * ```ts
   * const credentialSet =
   *   await client.vulnerabilityScanner.credentialSets.update(
   *     '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
   *     {
   *       account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *       name: 'Production API credentials',
   *     },
   *   );
   * ```
   */
  update(
    credentialSetId: string,
    params: CredentialSetUpdateParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<CredentialSetUpdateResponse> {
    const { account_id, ...body } = params;
    return (
      this._client.put(`/accounts/${account_id}/vuln_scanner/credential_sets/${credentialSetId}`, {
        body,
        ...options,
      }) as Core.APIPromise<{ result: CredentialSetUpdateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Returns all credential sets for the account.
   *
   * @example
   * ```ts
   * // Automatically fetches more pages as needed.
   * for await (const credentialSetListResponse of client.vulnerabilityScanner.credentialSets.list(
   *   { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   * )) {
   *   // ...
   * }
   * ```
   */
  list(
    params: CredentialSetListParams,
    options?: Core.RequestOptions,
  ): Core.PagePromise<CredentialSetListResponsesV4PagePaginationArray, CredentialSetListResponse> {
    const { account_id, ...query } = params;
    return this._client.getAPIList(
      `/accounts/${account_id}/vuln_scanner/credential_sets`,
      CredentialSetListResponsesV4PagePaginationArray,
      { query, ...options },
    );
  }

  /**
   * Deletes a credential set and all of its credentials.
   *
   * @example
   * ```ts
   * const credentialSet =
   *   await client.vulnerabilityScanner.credentialSets.delete(
   *     '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  delete(
    credentialSetId: string,
    params: CredentialSetDeleteParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<CredentialSetDeleteResponse | null> {
    const { account_id } = params;
    return (
      this._client.delete(
        `/accounts/${account_id}/vuln_scanner/credential_sets/${credentialSetId}`,
        options,
      ) as Core.APIPromise<{ result: CredentialSetDeleteResponse | null }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Updates a credential set with only the provided fields; omitted fields remain
   * unchanged.
   *
   * @example
   * ```ts
   * const response =
   *   await client.vulnerabilityScanner.credentialSets.edit(
   *     '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  edit(
    credentialSetId: string,
    params: CredentialSetEditParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<CredentialSetEditResponse> {
    const { account_id, ...body } = params;
    return (
      this._client.patch(`/accounts/${account_id}/vuln_scanner/credential_sets/${credentialSetId}`, {
        body,
        ...options,
      }) as Core.APIPromise<{ result: CredentialSetEditResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Returns a single credential set by ID.
   *
   * @example
   * ```ts
   * const credentialSet =
   *   await client.vulnerabilityScanner.credentialSets.get(
   *     '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  get(
    credentialSetId: string,
    params: CredentialSetGetParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<CredentialSetGetResponse> {
    const { account_id } = params;
    return (
      this._client.get(
        `/accounts/${account_id}/vuln_scanner/credential_sets/${credentialSetId}`,
        options,
      ) as Core.APIPromise<{ result: CredentialSetGetResponse }>
    )._thenUnwrap((obj) => obj.result);
  }
}

export class CredentialSetListResponsesV4PagePaginationArray extends V4PagePaginationArray<CredentialSetListResponse> {}

export interface CredentialSetCreateResponse {
  /**
   * Credential set identifier.
   */
  id: string;

  /**
   * Human-readable name.
   */
  name: string;
}

export interface CredentialSetUpdateResponse {
  /**
   * Credential set identifier.
   */
  id: string;

  /**
   * Human-readable name.
   */
  name: string;
}

export interface CredentialSetListResponse {
  /**
   * Credential set identifier.
   */
  id: string;

  /**
   * Human-readable name.
   */
  name: string;
}

export type CredentialSetDeleteResponse = unknown;

export interface CredentialSetEditResponse {
  /**
   * Credential set identifier.
   */
  id: string;

  /**
   * Human-readable name.
   */
  name: string;
}

export interface CredentialSetGetResponse {
  /**
   * Credential set identifier.
   */
  id: string;

  /**
   * Human-readable name.
   */
  name: string;
}

export interface CredentialSetCreateParams {
  /**
   * Path param: Identifier.
   */
  account_id: string;

  /**
   * Body param: Human-readable name.
   */
  name: string;
}

export interface CredentialSetUpdateParams {
  /**
   * Path param: Identifier.
   */
  account_id: string;

  /**
   * Body param: Human-readable name.
   */
  name: string;
}

export interface CredentialSetListParams extends V4PagePaginationArrayParams {
  /**
   * Path param: Identifier.
   */
  account_id: string;
}

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

export interface CredentialSetEditParams {
  /**
   * Path param: Identifier.
   */
  account_id: string;

  /**
   * Body param: Human-readable name.
   */
  name?: string;
}

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

CredentialSets.CredentialSetListResponsesV4PagePaginationArray =
  CredentialSetListResponsesV4PagePaginationArray;
CredentialSets.Credentials = Credentials;
CredentialSets.CredentialListResponsesV4PagePaginationArray = CredentialListResponsesV4PagePaginationArray;

export declare namespace CredentialSets {
  export {
    type CredentialSetCreateResponse as CredentialSetCreateResponse,
    type CredentialSetUpdateResponse as CredentialSetUpdateResponse,
    type CredentialSetListResponse as CredentialSetListResponse,
    type CredentialSetDeleteResponse as CredentialSetDeleteResponse,
    type CredentialSetEditResponse as CredentialSetEditResponse,
    type CredentialSetGetResponse as CredentialSetGetResponse,
    CredentialSetListResponsesV4PagePaginationArray as CredentialSetListResponsesV4PagePaginationArray,
    type CredentialSetCreateParams as CredentialSetCreateParams,
    type CredentialSetUpdateParams as CredentialSetUpdateParams,
    type CredentialSetListParams as CredentialSetListParams,
    type CredentialSetDeleteParams as CredentialSetDeleteParams,
    type CredentialSetEditParams as CredentialSetEditParams,
    type CredentialSetGetParams as CredentialSetGetParams,
  };

  export {
    Credentials as Credentials,
    type CredentialCreateResponse as CredentialCreateResponse,
    type CredentialUpdateResponse as CredentialUpdateResponse,
    type CredentialListResponse as CredentialListResponse,
    type CredentialDeleteResponse as CredentialDeleteResponse,
    type CredentialEditResponse as CredentialEditResponse,
    type CredentialGetResponse as CredentialGetResponse,
    CredentialListResponsesV4PagePaginationArray as CredentialListResponsesV4PagePaginationArray,
    type CredentialCreateParams as CredentialCreateParams,
    type CredentialUpdateParams as CredentialUpdateParams,
    type CredentialListParams as CredentialListParams,
    type CredentialDeleteParams as CredentialDeleteParams,
    type CredentialEditParams as CredentialEditParams,
    type CredentialGetParams as CredentialGetParams,
  };
}
