/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type RatelimitOverride = {
  /**
   * The unique identifier of this specific rate limit override. This ID is generated when the override is created and can be used for management operations like updating or deleting the override.
   */
  overrideId: string;
  /**
   * The duration in milliseconds for this override's rate limit window. This may differ from the default duration for the namespace, allowing custom time windows for specific entities. After this duration elapses, the rate limit counter for affected identifiers resets to zero.
   */
  duration: number;
  /**
   * The identifier pattern this override applies to. This determines which entities receive the custom rate limit.
   *
   * @remarks
   *
   * This can be:
   * - An exact identifier for a specific entity
   * - A pattern with wildcards for matching multiple entities
   *
   * Wildcard examples:
   * - 'admin_*' matches any identifier starting with 'admin_'
   * - '*_test' matches any identifier ending with '_test'
   * - '*premium*' matches any identifier containing 'premium'
   *
   * More complex patterns can combine multiple wildcards. Detailed documentation on pattern matching rules is available at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules
   */
  identifier: string;
  /**
   * The maximum number of requests allowed for entities matching this override. This replaces the default limit for the namespace when applied.
   *
   * @remarks
   *
   * Common use cases:
   * - Higher limits for premium customers
   * - Reduced limits for abusive or suspicious entities
   * - Zero limit to completely block specific patterns
   * - Custom tier-based limits for different customer segments
   */
  limit: number;
};

/** @internal */
export const RatelimitOverride$inboundSchema: z.ZodType<
  RatelimitOverride,
  z.ZodTypeDef,
  unknown
> = z.object({
  overrideId: z.string(),
  duration: z.number().int(),
  identifier: z.string(),
  limit: z.number().int(),
});

export function ratelimitOverrideFromJSON(
  jsonString: string,
): SafeParseResult<RatelimitOverride, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => RatelimitOverride$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'RatelimitOverride' from JSON`,
  );
}
