// File generated from our OpenAPI spec by Stainless.

import * as Core from 'cloudflare/core';
import { APIResource } from 'cloudflare/resource';
import * as LocationsAPI from 'cloudflare/resources/gateways/locations';

export class Locations extends APIResource {
  /**
   * Updates a configured Zero Trust Gateway location.
   */
  update(
    accountId: unknown,
    locationId: unknown,
    body: LocationUpdateParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<LocationUpdateResponse> {
    return (
      this._client.put(`/accounts/${accountId}/gateway/locations/${locationId}`, {
        body,
        ...options,
      }) as Core.APIPromise<{ result: LocationUpdateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Deletes a configured Zero Trust Gateway location.
   */
  delete(
    accountId: unknown,
    locationId: unknown,
    options?: Core.RequestOptions,
  ): Core.APIPromise<LocationDeleteResponse> {
    return (
      this._client.delete(
        `/accounts/${accountId}/gateway/locations/${locationId}`,
        options,
      ) as Core.APIPromise<{ result: LocationDeleteResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Fetches a single Zero Trust Gateway location.
   */
  get(
    accountId: unknown,
    locationId: unknown,
    options?: Core.RequestOptions,
  ): Core.APIPromise<LocationGetResponse> {
    return (
      this._client.get(`/accounts/${accountId}/gateway/locations/${locationId}`, options) as Core.APIPromise<{
        result: LocationGetResponse;
      }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Creates a new Zero Trust Gateway location.
   */
  zeroTrustGatewayLocationsCreateZeroTrustGatewayLocation(
    accountId: unknown,
    body: LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationResponse> {
    return (
      this._client.post(`/accounts/${accountId}/gateway/locations`, { body, ...options }) as Core.APIPromise<{
        result: LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationResponse;
      }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Fetches Zero Trust Gateway locations for an account.
   */
  zeroTrustGatewayLocationsListZeroTrustGatewayLocations(
    accountId: unknown,
    options?: Core.RequestOptions,
  ): Core.APIPromise<LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponse | null> {
    return (
      this._client.get(`/accounts/${accountId}/gateway/locations`, options) as Core.APIPromise<{
        result: LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponse | null;
      }>
    )._thenUnwrap((obj) => obj.result);
  }
}

export interface LocationUpdateResponse {
  id?: unknown;

  /**
   * True if the location is the default location.
   */
  client_default?: boolean;

  created_at?: string;

  /**
   * The DNS over HTTPS domain to send DNS requests to. This field is auto-generated
   * by Gateway.
   */
  doh_subdomain?: string;

  /**
   * True if the location needs to resolve EDNS queries.
   */
  ecs_support?: boolean;

  /**
   * IPV6 destination ip assigned to this location. DNS requests sent to this IP will
   * counted as the request under this location. This field is auto-generated by
   * Gateway.
   */
  ip?: string;

  /**
   * The name of the location.
   */
  name?: string;

  /**
   * A list of network ranges that requests from this location would originate from.
   */
  networks?: Array<LocationUpdateResponse.Network>;

  updated_at?: string;
}

export namespace LocationUpdateResponse {
  export interface Network {
    /**
     * The IPv4 address or IPv4 CIDR. IPv4 CIDRs are limited to a maximum of /24.
     */
    network: string;
  }
}

export type LocationDeleteResponse = unknown | string;

export interface LocationGetResponse {
  id?: unknown;

  /**
   * True if the location is the default location.
   */
  client_default?: boolean;

  created_at?: string;

  /**
   * The DNS over HTTPS domain to send DNS requests to. This field is auto-generated
   * by Gateway.
   */
  doh_subdomain?: string;

  /**
   * True if the location needs to resolve EDNS queries.
   */
  ecs_support?: boolean;

  /**
   * IPV6 destination ip assigned to this location. DNS requests sent to this IP will
   * counted as the request under this location. This field is auto-generated by
   * Gateway.
   */
  ip?: string;

  /**
   * The name of the location.
   */
  name?: string;

  /**
   * A list of network ranges that requests from this location would originate from.
   */
  networks?: Array<LocationGetResponse.Network>;

  updated_at?: string;
}

export namespace LocationGetResponse {
  export interface Network {
    /**
     * The IPv4 address or IPv4 CIDR. IPv4 CIDRs are limited to a maximum of /24.
     */
    network: string;
  }
}

export interface LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationResponse {
  id?: unknown;

  /**
   * True if the location is the default location.
   */
  client_default?: boolean;

  created_at?: string;

  /**
   * The DNS over HTTPS domain to send DNS requests to. This field is auto-generated
   * by Gateway.
   */
  doh_subdomain?: string;

  /**
   * True if the location needs to resolve EDNS queries.
   */
  ecs_support?: boolean;

  /**
   * IPV6 destination ip assigned to this location. DNS requests sent to this IP will
   * counted as the request under this location. This field is auto-generated by
   * Gateway.
   */
  ip?: string;

  /**
   * The name of the location.
   */
  name?: string;

  /**
   * A list of network ranges that requests from this location would originate from.
   */
  networks?: Array<LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationResponse.Network>;

  updated_at?: string;
}

export namespace LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationResponse {
  export interface Network {
    /**
     * The IPv4 address or IPv4 CIDR. IPv4 CIDRs are limited to a maximum of /24.
     */
    network: string;
  }
}

export type LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponse =
  Array<LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponse.LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponseItem>;

export namespace LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponse {
  export interface LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponseItem {
    id?: unknown;

    /**
     * True if the location is the default location.
     */
    client_default?: boolean;

    created_at?: string;

    /**
     * The DNS over HTTPS domain to send DNS requests to. This field is auto-generated
     * by Gateway.
     */
    doh_subdomain?: string;

    /**
     * True if the location needs to resolve EDNS queries.
     */
    ecs_support?: boolean;

    /**
     * IPV6 destination ip assigned to this location. DNS requests sent to this IP will
     * counted as the request under this location. This field is auto-generated by
     * Gateway.
     */
    ip?: string;

    /**
     * The name of the location.
     */
    name?: string;

    /**
     * A list of network ranges that requests from this location would originate from.
     */
    networks?: Array<LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponseItem.Network>;

    updated_at?: string;
  }

  export namespace LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponseItem {
    export interface Network {
      /**
       * The IPv4 address or IPv4 CIDR. IPv4 CIDRs are limited to a maximum of /24.
       */
      network: string;
    }
  }
}

export interface LocationUpdateParams {
  /**
   * The name of the location.
   */
  name: string;

  /**
   * True if the location is the default location.
   */
  client_default?: boolean;

  /**
   * True if the location needs to resolve EDNS queries.
   */
  ecs_support?: boolean;

  /**
   * A list of network ranges that requests from this location would originate from.
   */
  networks?: Array<LocationUpdateParams.Network>;
}

export namespace LocationUpdateParams {
  export interface Network {
    /**
     * The IPv4 address or IPv4 CIDR. IPv4 CIDRs are limited to a maximum of /24.
     */
    network: string;
  }
}

export interface LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationParams {
  /**
   * The name of the location.
   */
  name: string;

  /**
   * True if the location is the default location.
   */
  client_default?: boolean;

  /**
   * True if the location needs to resolve EDNS queries.
   */
  ecs_support?: boolean;

  /**
   * A list of network ranges that requests from this location would originate from.
   */
  networks?: Array<LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationParams.Network>;
}

export namespace LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationParams {
  export interface Network {
    /**
     * The IPv4 address or IPv4 CIDR. IPv4 CIDRs are limited to a maximum of /24.
     */
    network: string;
  }
}

export namespace Locations {
  export import LocationUpdateResponse = LocationsAPI.LocationUpdateResponse;
  export import LocationDeleteResponse = LocationsAPI.LocationDeleteResponse;
  export import LocationGetResponse = LocationsAPI.LocationGetResponse;
  export import LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationResponse = LocationsAPI.LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationResponse;
  export import LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponse = LocationsAPI.LocationZeroTrustGatewayLocationsListZeroTrustGatewayLocationsResponse;
  export import LocationUpdateParams = LocationsAPI.LocationUpdateParams;
  export import LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationParams = LocationsAPI.LocationZeroTrustGatewayLocationsCreateZeroTrustGatewayLocationParams;
}
