// 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 BaseURLIgnorePatterns extends APIResource {
  static override readonly _key: readonly ['emailSecurity', 'settings', 'urlIgnorePatterns'] = Object.freeze([
    'emailSecurity',
    'settings',
    'urlIgnorePatterns',
  ] as const);

  /**
   * Creates a new URL rewrite ignore pattern. URLs matching this pattern will not be
   * rewritten.
   *
   * @example
   * ```ts
   * const urlIgnorePattern =
   *   await client.emailSecurity.settings.urlIgnorePatterns.create(
   *     {
   *       account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *       pattern: 'https://example\\.com/.*',
   *     },
   *   );
   * ```
   */
  create(
    params: URLIgnorePatternCreateParams,
    options?: RequestOptions,
  ): APIPromise<URLIgnorePatternCreateResponse> {
    const { account_id, ...body } = params;
    return (
      this._client.post(path`/accounts/${account_id}/email-security/settings/url_ignore_patterns`, {
        body,
        ...options,
      }) as APIPromise<{ result: URLIgnorePatternCreateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Returns a paginated list of URL rewrite ignore patterns for the account. URLs
   * matching these patterns will not be rewritten.
   *
   * @example
   * ```ts
   * // Automatically fetches more pages as needed.
   * for await (const urlIgnorePatternListResponse of client.emailSecurity.settings.urlIgnorePatterns.list(
   *   { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   * )) {
   *   // ...
   * }
   * ```
   */
  list(
    params: URLIgnorePatternListParams,
    options?: RequestOptions,
  ): PagePromise<URLIgnorePatternListResponsesV4PagePaginationArray, URLIgnorePatternListResponse> {
    const { account_id, ...query } = params;
    return this._client.getAPIList(
      path`/accounts/${account_id}/email-security/settings/url_ignore_patterns`,
      V4PagePaginationArray<URLIgnorePatternListResponse>,
      { query, ...options },
    );
  }

  /**
   * Removes a URL rewrite ignore pattern. After deletion, URLs matching this pattern
   * will be rewritten again.
   *
   * @example
   * ```ts
   * const urlIgnorePattern =
   *   await client.emailSecurity.settings.urlIgnorePatterns.delete(
   *     'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  delete(
    patternID: string,
    params: URLIgnorePatternDeleteParams,
    options?: RequestOptions,
  ): APIPromise<URLIgnorePatternDeleteResponse> {
    const { account_id } = params;
    return (
      this._client.delete(
        path`/accounts/${account_id}/email-security/settings/url_ignore_patterns/${patternID}`,
        options,
      ) as APIPromise<{ result: URLIgnorePatternDeleteResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Updates an existing URL rewrite ignore pattern. Only provided fields will be
   * modified.
   *
   * @example
   * ```ts
   * const response =
   *   await client.emailSecurity.settings.urlIgnorePatterns.edit(
   *     'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  edit(
    patternID: string,
    params: URLIgnorePatternEditParams,
    options?: RequestOptions,
  ): APIPromise<URLIgnorePatternEditResponse> {
    const { account_id, ...body } = params;
    return (
      this._client.patch(
        path`/accounts/${account_id}/email-security/settings/url_ignore_patterns/${patternID}`,
        { body, ...options },
      ) as APIPromise<{ result: URLIgnorePatternEditResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Returns a single URL rewrite ignore pattern by its identifier.
   *
   * @example
   * ```ts
   * const urlIgnorePattern =
   *   await client.emailSecurity.settings.urlIgnorePatterns.get(
   *     'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
   *     { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   *   );
   * ```
   */
  get(
    patternID: string,
    params: URLIgnorePatternGetParams,
    options?: RequestOptions,
  ): APIPromise<URLIgnorePatternGetResponse> {
    const { account_id } = params;
    return (
      this._client.get(
        path`/accounts/${account_id}/email-security/settings/url_ignore_patterns/${patternID}`,
        options,
      ) as APIPromise<{ result: URLIgnorePatternGetResponse }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class URLIgnorePatterns extends BaseURLIgnorePatterns {}

export type URLIgnorePatternListResponsesV4PagePaginationArray =
  V4PagePaginationArray<URLIgnorePatternListResponse>;

/**
 * A URL ignore pattern that exempts matching URLs from Email Security's URL
 * rewriting.
 */
export interface URLIgnorePatternCreateResponse {
  /**
   * URL ignore pattern identifier.
   */
  id: string;

  created_at: string;

  /**
   * Regular expression identifying URLs to exempt from rewriting.
   */
  pattern: string;

  /**
   * Optional note describing the reason for the ignore pattern.
   */
  comments?: string | null;

  /**
   * @deprecated Use `modified_at` instead.
   */
  last_modified?: string;

  modified_at?: string;
}

/**
 * A URL ignore pattern that exempts matching URLs from Email Security's URL
 * rewriting.
 */
export interface URLIgnorePatternListResponse {
  /**
   * URL ignore pattern identifier.
   */
  id: string;

  created_at: string;

  /**
   * Regular expression identifying URLs to exempt from rewriting.
   */
  pattern: string;

  /**
   * Optional note describing the reason for the ignore pattern.
   */
  comments?: string | null;

  /**
   * @deprecated Use `modified_at` instead.
   */
  last_modified?: string;

  modified_at?: string;
}

export interface URLIgnorePatternDeleteResponse {
  /**
   * URL ignore pattern identifier.
   */
  id: string;
}

/**
 * A URL ignore pattern that exempts matching URLs from Email Security's URL
 * rewriting.
 */
export interface URLIgnorePatternEditResponse {
  /**
   * URL ignore pattern identifier.
   */
  id: string;

  created_at: string;

  /**
   * Regular expression identifying URLs to exempt from rewriting.
   */
  pattern: string;

  /**
   * Optional note describing the reason for the ignore pattern.
   */
  comments?: string | null;

  /**
   * @deprecated Use `modified_at` instead.
   */
  last_modified?: string;

  modified_at?: string;
}

/**
 * A URL ignore pattern that exempts matching URLs from Email Security's URL
 * rewriting.
 */
export interface URLIgnorePatternGetResponse {
  /**
   * URL ignore pattern identifier.
   */
  id: string;

  created_at: string;

  /**
   * Regular expression identifying URLs to exempt from rewriting.
   */
  pattern: string;

  /**
   * Optional note describing the reason for the ignore pattern.
   */
  comments?: string | null;

  /**
   * @deprecated Use `modified_at` instead.
   */
  last_modified?: string;

  modified_at?: string;
}

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

  /**
   * Body param: Regular expression identifying URLs to exempt from rewriting.
   */
  pattern: string;

  /**
   * Body param: Optional note describing the reason for the ignore pattern.
   */
  comments?: string | null;
}

export interface URLIgnorePatternListParams extends V4PagePaginationArrayParams {
  /**
   * Path param: Account identifier tag.
   */
  account_id: string;
}

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

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

  /**
   * Body param: Optional note describing the reason for the ignore pattern.
   */
  comments?: string | null;

  /**
   * Body param: Regular expression identifying URLs to exempt from rewriting.
   */
  pattern?: string;
}

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

export declare namespace URLIgnorePatterns {
  export {
    type URLIgnorePatternCreateResponse as URLIgnorePatternCreateResponse,
    type URLIgnorePatternListResponse as URLIgnorePatternListResponse,
    type URLIgnorePatternDeleteResponse as URLIgnorePatternDeleteResponse,
    type URLIgnorePatternEditResponse as URLIgnorePatternEditResponse,
    type URLIgnorePatternGetResponse as URLIgnorePatternGetResponse,
    type URLIgnorePatternListResponsesV4PagePaginationArray as URLIgnorePatternListResponsesV4PagePaginationArray,
    type URLIgnorePatternCreateParams as URLIgnorePatternCreateParams,
    type URLIgnorePatternListParams as URLIgnorePatternListParams,
    type URLIgnorePatternDeleteParams as URLIgnorePatternDeleteParams,
    type URLIgnorePatternEditParams as URLIgnorePatternEditParams,
    type URLIgnorePatternGetParams as URLIgnorePatternGetParams,
  };
}
