// 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 { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';

export class BasePreview extends APIResource {
  static override readonly _key: readonly ['emailSecurity', 'investigate', 'preview'] = Object.freeze([
    'emailSecurity',
    'investigate',
    'preview',
  ] as const);

  /**
   * Generates a preview image for a message that was not flagged as a detection. The
   * message is rendered from the copy in the recipient's mailbox, so this requires
   * an active integration and only works while the message is still in the
   * recipient's inbox. Returns a base64-encoded PNG screenshot of the email body.
   * For messages with a detection, use the detection preview endpoint instead.
   *
   * @example
   * ```ts
   * const preview =
   *   await client.emailSecurity.investigate.preview.create({
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     id: '4Njp3P0STMz2c02Q-2024-01-05T10:00:00-12345678',
   *   });
   * ```
   */
  create(params: PreviewCreateParams, options?: RequestOptions): APIPromise<PreviewCreateResponse> {
    const { account_id, ...body } = params;
    return (
      this._client.post(path`/accounts/${account_id}/email-security/investigate/preview`, {
        body,
        ...options,
      }) as APIPromise<{ result: PreviewCreateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Returns a preview of the message body as a base64-encoded PNG image for any
   * message with a detection. For messages without a detection, use the
   * non-detection preview endpoint instead.
   *
   * @example
   * ```ts
   * const preview =
   *   await client.emailSecurity.investigate.preview.get(
   *     '4Njp3P0STMz2c02Q-2024-01-05T10:00:00-12345678',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  get(
    investigateID: string,
    params: PreviewGetParams,
    options?: RequestOptions,
  ): APIPromise<PreviewGetResponse> {
    const { account_id } = params;
    return (
      this._client.get(
        path`/accounts/${account_id}/email-security/investigate/${investigateID}/preview`,
        options,
      ) as APIPromise<{ result: PreviewGetResponse }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class Preview extends BasePreview {}

export interface PreviewCreateResponse {
  /**
   * A base64 encoded PNG image of the email.
   */
  screenshot: string;
}

export interface PreviewGetResponse {
  /**
   * A base64 encoded PNG image of the email.
   */
  screenshot: string;
}

export interface PreviewCreateParams {
  /**
   * Path param: Account identifier tag.
   */
  account_id: string;

  /**
   * Body param: Unique identifier for a message retrieved from investigation.
   */
  id: string;
}

export interface PreviewGetParams {
  /**
   * Account identifier tag.
   */
  account_id: string;
}

export declare namespace Preview {
  export {
    type PreviewCreateResponse as PreviewCreateResponse,
    type PreviewGetResponse as PreviewGetResponse,
    type PreviewCreateParams as PreviewCreateParams,
    type PreviewGetParams as PreviewGetParams,
  };
}
