// 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,
  V4PagePaginationArray,
  type V4PagePaginationArrayParams,
} from '../../../../core/pagination';
import { RequestOptions } from '../../../../internal/request-options';
import { path } from '../../../../internal/utils/path';

export class BaseExports extends APIResource {
  static override readonly _key: readonly ['zeroTrust', 'casb', 'posture', 'exports'] = Object.freeze([
    'zeroTrust',
    'casb',
    'posture',
    'exports',
  ] as const);

  /**
   * List all export jobs for a given requestor's organization
   *
   * @example
   * ```ts
   * // Automatically fetches more pages as needed.
   * for await (const exportListResponse of client.zeroTrust.casb.posture.exports.list(
   *   { account_id: '46148281d8a93d002ef242d8b0d5f9f6' },
   * )) {
   *   // ...
   * }
   * ```
   */
  list(
    params: ExportListParams,
    options?: RequestOptions,
  ): PagePromise<ExportListResponsesV4PagePaginationArray, ExportListResponse> {
    const { account_id, ...query } = params;
    return this._client.getAPIList(
      path`/accounts/${account_id}/data-security/posture/exports`,
      V4PagePaginationArray<ExportListResponse>,
      { query, ...options },
    );
  }

  /**
   * Retrieves a single export job by its unique identifier
   *
   * @example
   * ```ts
   * const _export =
   *   await client.zeroTrust.casb.posture.exports.get('id', {
   *     account_id: '46148281d8a93d002ef242d8b0d5f9f6',
   *   });
   * ```
   */
  get(id: string, params: ExportGetParams, options?: RequestOptions): APIPromise<ExportGetResponse> {
    const { account_id } = params;
    return (
      this._client.get(
        path`/accounts/${account_id}/data-security/posture/exports/${id}`,
        options,
      ) as APIPromise<{ result: ExportGetResponse }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class Exports extends BaseExports {}

export type ExportListResponsesV4PagePaginationArray = V4PagePaginationArray<ExportListResponse>;

/**
 * Information about an export job.
 */
export interface ExportListResponse {
  /**
   * Unique identifier for the export job.
   */
  id: string;

  /**
   * Status of an export job.
   */
  status: 'Pending' | 'Success' | 'Failure' | 'Rescheduled' | 'In-Progress';

  /**
   * Type of export job.
   */
  type: 'finding' | 'findingInstance' | 'content' | 'remediationJob';

  /**
   * ID of the export-requesting user.
   */
  user_id: string;

  /**
   * The URL by which the successfully created export can be downloaded by the end
   * users.
   */
  download_url?: string | null;

  /**
   * Contains information on errors which may have occurred during export creation.
   */
  errors?: string | null;

  /**
   * The base name of the file that is/was generated by the export job.
   */
  file_name?: string | null;

  /**
   * The full path of the file that is stored within external storage (currently R2).
   */
  file_path?: string | null;
}

/**
 * Information about an export job.
 */
export interface ExportGetResponse {
  /**
   * Unique identifier for the export job.
   */
  id: string;

  /**
   * Status of an export job.
   */
  status: 'Pending' | 'Success' | 'Failure' | 'Rescheduled' | 'In-Progress';

  /**
   * Type of export job.
   */
  type: 'finding' | 'findingInstance' | 'content' | 'remediationJob';

  /**
   * ID of the export-requesting user.
   */
  user_id: string;

  /**
   * The URL by which the successfully created export can be downloaded by the end
   * users.
   */
  download_url?: string | null;

  /**
   * Contains information on errors which may have occurred during export creation.
   */
  errors?: string | null;

  /**
   * The base name of the file that is/was generated by the export job.
   */
  file_name?: string | null;

  /**
   * The full path of the file that is stored within external storage (currently R2).
   */
  file_path?: string | null;
}

export interface ExportListParams extends V4PagePaginationArrayParams {
  /**
   * Path param: Cloudflare account ID for the user making the request.
   */
  account_id: string;

  /**
   * Query param: Filter on export job's status
   */
  status?: 'Pending' | 'Success' | 'Failure' | 'Rescheduled' | 'In-Progress';
}

export interface ExportGetParams {
  /**
   * Cloudflare account ID for the user making the request.
   */
  account_id: string;
}

export declare namespace Exports {
  export {
    type ExportListResponse as ExportListResponse,
    type ExportGetResponse as ExportGetResponse,
    type ExportListResponsesV4PagePaginationArray as ExportListResponsesV4PagePaginationArray,
    type ExportListParams as ExportListParams,
    type ExportGetParams as ExportGetParams,
  };
}
