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

import { APIResource } from '../../../resource';
import { isRequestOptions } from '../../../core';
import * as Core from '../../../core';
import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../../pagination';

export class DEXTests extends APIResource {
  /**
   * Create a DEX test.
   *
   * @example
   * ```ts
   * const dexTest =
   *   await client.zeroTrust.devices.dexTests.create({
   *     account_id: '01a7362d577a6c3019a474fd6f485823',
   *     data: {
   *       host: 'https://dash.cloudflare.com',
   *       kind: 'http',
   *     },
   *     enabled: true,
   *     interval: '30m',
   *     name: 'HTTP dash health check',
   *   });
   * ```
   */
  create(params: DEXTestCreateParams, options?: Core.RequestOptions): Core.APIPromise<DEXTestCreateResponse> {
    const { account_id = this._client.accountId, ...body } = params;
    return (
      this._client.post(`/accounts/${account_id}/dex/devices/dex_tests`, {
        body,
        ...options,
      }) as Core.APIPromise<{ result: DEXTestCreateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Update a DEX test.
   *
   * @example
   * ```ts
   * const dexTest =
   *   await client.zeroTrust.devices.dexTests.update(
   *     'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
   *     {
   *       account_id: '01a7362d577a6c3019a474fd6f485823',
   *       data: {
   *         host: 'https://dash.cloudflare.com',
   *         kind: 'http',
   *       },
   *       enabled: true,
   *       interval: '30m',
   *       name: 'HTTP dash health check',
   *     },
   *   );
   * ```
   */
  update(
    dexTestId: string,
    params: DEXTestUpdateParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<DEXTestUpdateResponse> {
    const { account_id = this._client.accountId, ...body } = params;
    return (
      this._client.put(`/accounts/${account_id}/dex/devices/dex_tests/${dexTestId}`, {
        body,
        ...options,
      }) as Core.APIPromise<{ result: DEXTestUpdateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Fetch all DEX tests
   *
   * @example
   * ```ts
   * // Automatically fetches more pages as needed.
   * for await (const dexTestListResponse of client.zeroTrust.devices.dexTests.list(
   *   { account_id: '01a7362d577a6c3019a474fd6f485823' },
   * )) {
   *   // ...
   * }
   * ```
   */
  list(
    params?: DEXTestListParams,
    options?: Core.RequestOptions,
  ): Core.PagePromise<DEXTestListResponsesV4PagePaginationArray, DEXTestListResponse>;
  list(
    options?: Core.RequestOptions,
  ): Core.PagePromise<DEXTestListResponsesV4PagePaginationArray, DEXTestListResponse>;
  list(
    params: DEXTestListParams | Core.RequestOptions = {},
    options?: Core.RequestOptions,
  ): Core.PagePromise<DEXTestListResponsesV4PagePaginationArray, DEXTestListResponse> {
    if (isRequestOptions(params)) {
      return this.list({}, params);
    }
    const { account_id = this._client.accountId, ...query } = params;
    return this._client.getAPIList(
      `/accounts/${account_id}/dex/devices/dex_tests`,
      DEXTestListResponsesV4PagePaginationArray,
      { query, ...options },
    );
  }

  /**
   * Delete a Device DEX test. Returns the remaining device dex tests for the
   * account.
   *
   * @example
   * ```ts
   * const dexTest =
   *   await client.zeroTrust.devices.dexTests.delete(
   *     'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
   *     { account_id: '01a7362d577a6c3019a474fd6f485823' },
   *   );
   * ```
   */
  delete(
    dexTestId: string,
    params?: DEXTestDeleteParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<DEXTestDeleteResponse>;
  delete(dexTestId: string, options?: Core.RequestOptions): Core.APIPromise<DEXTestDeleteResponse>;
  delete(
    dexTestId: string,
    params: DEXTestDeleteParams | Core.RequestOptions = {},
    options?: Core.RequestOptions,
  ): Core.APIPromise<DEXTestDeleteResponse> {
    if (isRequestOptions(params)) {
      return this.delete(dexTestId, {}, params);
    }
    const { account_id = this._client.accountId } = params;
    return (
      this._client.delete(
        `/accounts/${account_id}/dex/devices/dex_tests/${dexTestId}`,
        options,
      ) as Core.APIPromise<{ result: DEXTestDeleteResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Fetch a single DEX test.
   *
   * @example
   * ```ts
   * const dexTest = await client.zeroTrust.devices.dexTests.get(
   *   '372e67954025e0ba6aaa6d586b9e0b59',
   *   { account_id: '01a7362d577a6c3019a474fd6f485823' },
   * );
   * ```
   */
  get(
    dexTestId: string,
    params?: DEXTestGetParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<DEXTestGetResponse>;
  get(dexTestId: string, options?: Core.RequestOptions): Core.APIPromise<DEXTestGetResponse>;
  get(
    dexTestId: string,
    params: DEXTestGetParams | Core.RequestOptions = {},
    options?: Core.RequestOptions,
  ): Core.APIPromise<DEXTestGetResponse> {
    if (isRequestOptions(params)) {
      return this.get(dexTestId, {}, params);
    }
    const { account_id = this._client.accountId } = params;
    return (
      this._client.get(
        `/accounts/${account_id}/dex/devices/dex_tests/${dexTestId}`,
        options,
      ) as Core.APIPromise<{ result: DEXTestGetResponse }>
    )._thenUnwrap((obj) => obj.result);
  }
}

export class DEXTestListResponsesV4PagePaginationArray extends V4PagePaginationArray<DEXTestListResponse> {}

/**
 * The configuration object which contains the details for the WARP client to
 * conduct the test.
 */
export interface SchemaData {
  /**
   * The desired endpoint to test.
   */
  host?: string;

  /**
   * The type of test.
   */
  kind?: string;

  /**
   * The HTTP request method type.
   */
  method?: string;
}

export interface SchemaHTTP {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  data: SchemaData;

  /**
   * Determines whether or not the test is active.
   */
  enabled: boolean;

  /**
   * How often the test will run.
   */
  interval: string;

  /**
   * The name of the DEX test. Must be unique.
   */
  name: string;

  /**
   * Additional details about the test.
   */
  description?: string;

  /**
   * Device settings profiles targeted by this test.
   */
  target_policies?: Array<SchemaHTTP.TargetPolicy>;

  targeted?: boolean;

  /**
   * The unique identifier for the test.
   */
  test_id?: string;
}

export namespace SchemaHTTP {
  export interface TargetPolicy {
    /**
     * The id of the device settings profile.
     */
    id?: string;

    /**
     * Whether the profile is the account default.
     */
    default?: boolean;

    /**
     * The name of the device settings profile.
     */
    name?: string;
  }
}

export interface DEXTestCreateResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  data: DEXTestCreateResponse.Data;

  /**
   * Determines whether or not the test is active.
   */
  enabled: boolean;

  /**
   * How often the test will run.
   */
  interval: string;

  /**
   * The name of the DEX test. Must be unique.
   */
  name: string;

  /**
   * Additional details about the test.
   */
  description?: string;

  /**
   * DEX rules targeted by this test
   */
  target_policies?: Array<DEXTestCreateResponse.TargetPolicy>;

  targeted?: boolean;

  /**
   * The unique identifier for the test.
   */
  test_id?: string;
}

export namespace DEXTestCreateResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  export interface Data {
    /**
     * The desired endpoint to test.
     */
    host: string;

    /**
     * The type of test.
     */
    kind: 'http' | 'traceroute';

    /**
     * The HTTP request method type.
     */
    method?: 'GET';
  }

  export interface TargetPolicy {
    /**
     * API Resource UUID tag.
     */
    id: string;

    /**
     * Whether the DEX rule is the account default
     */
    default?: boolean;

    /**
     * The name of the DEX rule
     */
    name?: string;
  }
}

export interface DEXTestUpdateResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  data: DEXTestUpdateResponse.Data;

  /**
   * Determines whether or not the test is active.
   */
  enabled: boolean;

  /**
   * How often the test will run.
   */
  interval: string;

  /**
   * The name of the DEX test. Must be unique.
   */
  name: string;

  /**
   * Additional details about the test.
   */
  description?: string;

  /**
   * DEX rules targeted by this test
   */
  target_policies?: Array<DEXTestUpdateResponse.TargetPolicy>;

  targeted?: boolean;

  /**
   * The unique identifier for the test.
   */
  test_id?: string;
}

export namespace DEXTestUpdateResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  export interface Data {
    /**
     * The desired endpoint to test.
     */
    host: string;

    /**
     * The type of test.
     */
    kind: 'http' | 'traceroute';

    /**
     * The HTTP request method type.
     */
    method?: 'GET';
  }

  export interface TargetPolicy {
    /**
     * API Resource UUID tag.
     */
    id: string;

    /**
     * Whether the DEX rule is the account default
     */
    default?: boolean;

    /**
     * The name of the DEX rule
     */
    name?: string;
  }
}

export interface DEXTestListResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  data: DEXTestListResponse.Data;

  /**
   * Determines whether or not the test is active.
   */
  enabled: boolean;

  /**
   * How often the test will run.
   */
  interval: string;

  /**
   * The name of the DEX test. Must be unique.
   */
  name: string;

  /**
   * Additional details about the test.
   */
  description?: string;

  /**
   * DEX rules targeted by this test
   */
  target_policies?: Array<DEXTestListResponse.TargetPolicy>;

  targeted?: boolean;

  /**
   * The unique identifier for the test.
   */
  test_id?: string;
}

export namespace DEXTestListResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  export interface Data {
    /**
     * The desired endpoint to test.
     */
    host: string;

    /**
     * The type of test.
     */
    kind: 'http' | 'traceroute';

    /**
     * The HTTP request method type.
     */
    method?: 'GET';
  }

  export interface TargetPolicy {
    /**
     * API Resource UUID tag.
     */
    id: string;

    /**
     * Whether the DEX rule is the account default
     */
    default?: boolean;

    /**
     * The name of the DEX rule
     */
    name?: string;
  }
}

export interface DEXTestDeleteResponse {
  dex_tests?: Array<DEXTestDeleteResponse.DEXTest>;
}

export namespace DEXTestDeleteResponse {
  export interface DEXTest {
    /**
     * The configuration object which contains the details for the WARP client to
     * conduct the test.
     */
    data: DEXTest.Data;

    /**
     * Determines whether or not the test is active.
     */
    enabled: boolean;

    /**
     * How often the test will run.
     */
    interval: string;

    /**
     * The name of the DEX test. Must be unique.
     */
    name: string;

    /**
     * Additional details about the test.
     */
    description?: string;

    /**
     * DEX rules targeted by this test
     */
    target_policies?: Array<DEXTest.TargetPolicy>;

    targeted?: boolean;

    /**
     * The unique identifier for the test.
     */
    test_id?: string;
  }

  export namespace DEXTest {
    /**
     * The configuration object which contains the details for the WARP client to
     * conduct the test.
     */
    export interface Data {
      /**
       * The desired endpoint to test.
       */
      host: string;

      /**
       * The type of test.
       */
      kind: 'http' | 'traceroute';

      /**
       * The HTTP request method type.
       */
      method?: 'GET';
    }

    export interface TargetPolicy {
      /**
       * API Resource UUID tag.
       */
      id: string;

      /**
       * Whether the DEX rule is the account default
       */
      default?: boolean;

      /**
       * The name of the DEX rule
       */
      name?: string;
    }
  }
}

export interface DEXTestGetResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  data: DEXTestGetResponse.Data;

  /**
   * Determines whether or not the test is active.
   */
  enabled: boolean;

  /**
   * How often the test will run.
   */
  interval: string;

  /**
   * The name of the DEX test. Must be unique.
   */
  name: string;

  /**
   * Additional details about the test.
   */
  description?: string;

  /**
   * DEX rules targeted by this test
   */
  target_policies?: Array<DEXTestGetResponse.TargetPolicy>;

  targeted?: boolean;

  /**
   * The unique identifier for the test.
   */
  test_id?: string;
}

export namespace DEXTestGetResponse {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  export interface Data {
    /**
     * The desired endpoint to test.
     */
    host: string;

    /**
     * The type of test.
     */
    kind: 'http' | 'traceroute';

    /**
     * The HTTP request method type.
     */
    method?: 'GET';
  }

  export interface TargetPolicy {
    /**
     * API Resource UUID tag.
     */
    id: string;

    /**
     * Whether the DEX rule is the account default
     */
    default?: boolean;

    /**
     * The name of the DEX rule
     */
    name?: string;
  }
}

export interface DEXTestCreateParams {
  /**
   * Path param
   */
  account_id?: string;

  /**
   * Body param: The configuration object which contains the details for the WARP
   * client to conduct the test.
   */
  data: DEXTestCreateParams.Data;

  /**
   * Body param: Determines whether or not the test is active.
   */
  enabled: boolean;

  /**
   * Body param: How often the test will run.
   */
  interval: string;

  /**
   * Body param: The name of the DEX test. Must be unique.
   */
  name: string;

  /**
   * Body param: Additional details about the test.
   */
  description?: string;

  /**
   * Body param: DEX rules targeted by this test
   */
  target_policies?: Array<DEXTestCreateParams.TargetPolicy>;

  /**
   * Body param
   */
  targeted?: boolean;
}

export namespace DEXTestCreateParams {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  export interface Data {
    /**
     * The desired endpoint to test.
     */
    host: string;

    /**
     * The type of test.
     */
    kind: 'http' | 'traceroute';

    /**
     * The HTTP request method type.
     */
    method?: 'GET';
  }

  export interface TargetPolicy {
    /**
     * API Resource UUID tag.
     */
    id: string;

    /**
     * Whether the DEX rule is the account default
     */
    default?: boolean;

    /**
     * The name of the DEX rule
     */
    name?: string;
  }
}

export interface DEXTestUpdateParams {
  /**
   * Path param
   */
  account_id?: string;

  /**
   * Body param: The configuration object which contains the details for the WARP
   * client to conduct the test.
   */
  data: DEXTestUpdateParams.Data;

  /**
   * Body param: Determines whether or not the test is active.
   */
  enabled: boolean;

  /**
   * Body param: How often the test will run.
   */
  interval: string;

  /**
   * Body param: The name of the DEX test. Must be unique.
   */
  name: string;

  /**
   * Body param: Additional details about the test.
   */
  description?: string;

  /**
   * Body param: DEX rules targeted by this test
   */
  target_policies?: Array<DEXTestUpdateParams.TargetPolicy>;

  /**
   * Body param
   */
  targeted?: boolean;
}

export namespace DEXTestUpdateParams {
  /**
   * The configuration object which contains the details for the WARP client to
   * conduct the test.
   */
  export interface Data {
    /**
     * The desired endpoint to test.
     */
    host: string;

    /**
     * The type of test.
     */
    kind: 'http' | 'traceroute';

    /**
     * The HTTP request method type.
     */
    method?: 'GET';
  }

  export interface TargetPolicy {
    /**
     * API Resource UUID tag.
     */
    id: string;

    /**
     * Whether the DEX rule is the account default
     */
    default?: boolean;

    /**
     * The name of the DEX rule
     */
    name?: string;
  }
}

export interface DEXTestListParams extends V4PagePaginationArrayParams {
  /**
   * Path param
   */
  account_id?: string;

  /**
   * Query param: Filter by test type
   */
  kind?: 'http' | 'traceroute';

  /**
   * Query param: Filter by test name
   */
  testName?: string;
}

export interface DEXTestDeleteParams {
  account_id?: string;
}

export interface DEXTestGetParams {
  account_id?: string;
}

DEXTests.DEXTestListResponsesV4PagePaginationArray = DEXTestListResponsesV4PagePaginationArray;

export declare namespace DEXTests {
  export {
    type SchemaData as SchemaData,
    type SchemaHTTP as SchemaHTTP,
    type DEXTestCreateResponse as DEXTestCreateResponse,
    type DEXTestUpdateResponse as DEXTestUpdateResponse,
    type DEXTestListResponse as DEXTestListResponse,
    type DEXTestDeleteResponse as DEXTestDeleteResponse,
    type DEXTestGetResponse as DEXTestGetResponse,
    DEXTestListResponsesV4PagePaginationArray as DEXTestListResponsesV4PagePaginationArray,
    type DEXTestCreateParams as DEXTestCreateParams,
    type DEXTestUpdateParams as DEXTestUpdateParams,
    type DEXTestListParams as DEXTestListParams,
    type DEXTestDeleteParams as DEXTestDeleteParams,
    type DEXTestGetParams as DEXTestGetParams,
  };
}
