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

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

export type RatelimitOverride = {
  /**
   * The id of the namespace.
   */
  namespaceId: string;
  /**
   * The id of the override.
   */
  overrideId: string;
  /**
   * The duration in milliseconds for the rate limit window.
   */
  duration: number;
  /**
   * Identifier of your user, this can be their userId, an email, an ip or anything else. Wildcards ( * ) can be used to match multiple identifiers, More info can be found at https://www.unkey.com/docs/ratelimiting/overrides#wildcard-rules
   */
  identifier: string;
  /**
   * The maximum number of requests allowed.
   */
  limit: number;
};

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

/** @internal */
export type RatelimitOverride$Outbound = {
  namespaceId: string;
  overrideId: string;
  duration: number;
  identifier: string;
  limit: number;
};

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

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace RatelimitOverride$ {
  /** @deprecated use `RatelimitOverride$inboundSchema` instead. */
  export const inboundSchema = RatelimitOverride$inboundSchema;
  /** @deprecated use `RatelimitOverride$outboundSchema` instead. */
  export const outboundSchema = RatelimitOverride$outboundSchema;
  /** @deprecated use `RatelimitOverride$Outbound` instead. */
  export type Outbound = RatelimitOverride$Outbound;
}

export function ratelimitOverrideToJSON(
  ratelimitOverride: RatelimitOverride,
): string {
  return JSON.stringify(
    RatelimitOverride$outboundSchema.parse(ratelimitOverride),
  );
}

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