// 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';

/**
 * @deprecated Please use the [Schema Validation Operations Settings](https://developers.cloudflare.com/api/resources/schema_validation/subresources/settings/subresources/operations/) APIs instead
 */
export class BaseSchemaValidation extends APIResource {
  static override readonly _key: readonly ['apiGateway', 'operations', 'schemaValidation'] = Object.freeze([
    'apiGateway',
    'operations',
    'schemaValidation',
  ] as const);

  /**
   * Updates operation-level schema validation settings on the zone. Deprecated; use
   * `/zones/{zone_id}/schema_validation/settings/operations/{operation_id}` instead.
   *
   * @deprecated Use [Schema Validation API](https://developers.cloudflare.com/api/resources/schema_validation/) instead.
   */
  update(
    operationID: string,
    params: SchemaValidationUpdateParams,
    options?: RequestOptions,
  ): APIPromise<SchemaValidationUpdateResponse> {
    const { zone_id, ...body } = params;
    return this._client.put(path`/zones/${zone_id}/api_gateway/operations/${operationID}/schema_validation`, {
      body,
      ...options,
    });
  }

  /**
   * Updates multiple operation-level schema validation settings on the zone.
   * Deprecated; use `/zones/{zone_id}/schema_validation/settings/operations`
   * instead.
   *
   * @deprecated Use [Schema Validation API](https://developers.cloudflare.com/api/resources/schema_validation/) instead.
   */
  edit(params: SchemaValidationEditParams, options?: RequestOptions): APIPromise<SettingsMultipleRequest> {
    const { zone_id, settings_multiple_request } = params;
    return (
      this._client.patch(path`/zones/${zone_id}/api_gateway/operations/schema_validation`, {
        body: settings_multiple_request,
        ...options,
      }) as APIPromise<{ result: SettingsMultipleRequest }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Retrieves operation-level schema validation settings on the zone. Deprecated;
   * use `/zones/{zone_id}/schema_validation/settings/operations/{operation_id}`
   * instead.
   *
   * @deprecated Use [Schema Validation API](https://developers.cloudflare.com/api/resources/schema_validation/) instead.
   */
  get(
    operationID: string,
    params: SchemaValidationGetParams,
    options?: RequestOptions,
  ): APIPromise<SchemaValidationGetResponse> {
    const { zone_id } = params;
    return this._client.get(
      path`/zones/${zone_id}/api_gateway/operations/${operationID}/schema_validation`,
      options,
    );
  }
}
/**
 * @deprecated Please use the [Schema Validation Operations Settings](https://developers.cloudflare.com/api/resources/schema_validation/subresources/settings/subresources/operations/) APIs instead
 */
export class SchemaValidation extends BaseSchemaValidation {}

export type SettingsMultipleRequest = { [key: string]: SettingsMultipleRequest.item };

export namespace SettingsMultipleRequest {
  /**
   * Operation ID to mitigation action mappings
   */
  export interface item {
    /**
     * When set, this applies a mitigation action to this operation
     *
     * - `log` log request when request does not conform to schema for this operation
     * - `block` deny access to the site when request does not conform to schema for
     *   this operation
     * - `none` will skip mitigation for this operation
     * - `null` indicates that no operation level mitigation is in place, see Zone
     *   Level Schema Validation Settings for mitigation action that will be applied
     */
    mitigation_action?: 'log' | 'block' | 'none' | null;
  }
}

export type SettingsMultipleRequestParam = { [key: string]: SettingsMultipleRequestParam.item };

export namespace SettingsMultipleRequestParam {
  /**
   * Operation ID to mitigation action mappings
   */
  export interface item {
    /**
     * When set, this applies a mitigation action to this operation
     *
     * - `log` log request when request does not conform to schema for this operation
     * - `block` deny access to the site when request does not conform to schema for
     *   this operation
     * - `none` will skip mitigation for this operation
     * - `null` indicates that no operation level mitigation is in place, see Zone
     *   Level Schema Validation Settings for mitigation action that will be applied
     */
    mitigation_action?: 'log' | 'block' | 'none' | null;
  }
}

export interface SchemaValidationUpdateResponse {
  /**
   * When set, this applies a mitigation action to this operation
   *
   * - `log` log request when request does not conform to schema for this operation
   * - `block` deny access to the site when request does not conform to schema for
   *   this operation
   * - `none` will skip mitigation for this operation
   * - `null` indicates that no operation level mitigation is in place, see Zone
   *   Level Schema Validation Settings for mitigation action that will be applied
   */
  mitigation_action?: 'log' | 'block' | 'none' | null;

  /**
   * UUID.
   */
  operation_id?: string;
}

export interface SchemaValidationGetResponse {
  /**
   * When set, this applies a mitigation action to this operation
   *
   * - `log` log request when request does not conform to schema for this operation
   * - `block` deny access to the site when request does not conform to schema for
   *   this operation
   * - `none` will skip mitigation for this operation
   * - `null` indicates that no operation level mitigation is in place, see Zone
   *   Level Schema Validation Settings for mitigation action that will be applied
   */
  mitigation_action?: 'log' | 'block' | 'none' | null;

  /**
   * UUID.
   */
  operation_id?: string;
}

export interface SchemaValidationUpdateParams {
  /**
   * Path param: Identifier.
   */
  zone_id: string;

  /**
   * Body param: When set, this applies a mitigation action to this operation
   *
   * - `log` log request when request does not conform to schema for this operation
   * - `block` deny access to the site when request does not conform to schema for
   *   this operation
   * - `none` will skip mitigation for this operation
   * - `null` indicates that no operation level mitigation is in place, see Zone
   *   Level Schema Validation Settings for mitigation action that will be applied
   */
  mitigation_action?: 'log' | 'block' | 'none' | null;
}

export interface SchemaValidationEditParams {
  /**
   * Path param: Identifier.
   */
  zone_id: string;

  /**
   * Body param
   */
  settings_multiple_request: SettingsMultipleRequestParam;
}

export interface SchemaValidationGetParams {
  /**
   * Identifier.
   */
  zone_id: string;
}

export declare namespace SchemaValidation {
  export {
    type SettingsMultipleRequest as SettingsMultipleRequest,
    type SchemaValidationUpdateResponse as SchemaValidationUpdateResponse,
    type SchemaValidationGetResponse as SchemaValidationGetResponse,
    type SchemaValidationUpdateParams as SchemaValidationUpdateParams,
    type SchemaValidationEditParams as SchemaValidationEditParams,
    type SchemaValidationGetParams as SchemaValidationGetParams,
  };
}
