/*
 * 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 * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * AI Gateway quota associated with an API key.
 */
export type APIKeyQuota = {
  /**
   * The unique identifier for the quota.
   */
  quotaEntityId: string;
  /**
   * The quota limit amount.
   */
  limitAmount: number;
  /**
   * The current amount spent against the quota.
   */
  currentSpend: number;
  /**
   * The current BYOK spend (tracked separately).
   */
  currentByokSpend: number;
  /**
   * Whether BYOK (Bring Your Own Key) spend counts against the quota.
   */
  includeByokInQuota: boolean;
  /**
   * How often the quota refreshes.
   */
  refreshPeriod: string;
  /**
   * Whether the quota is currently active.
   */
  active: boolean;
  /**
   * Whether the quota has been archived.
   */
  archived: boolean;
  /**
   * Spend percentages (a subset of [50, 75, 100]) at which to send a spend alert. Empty or undefined disables alerts.
   */
  alertThresholds?: Array<number> | undefined;
  /**
   * Timestamp (in milliseconds) of when the quota was created.
   */
  createdAt: number;
  /**
   * Timestamp (in milliseconds) of when the quota was last updated.
   */
  updatedAt: number;
};

/** @internal */
export const APIKeyQuota$inboundSchema: z.ZodType<
  APIKeyQuota,
  z.ZodTypeDef,
  unknown
> = z.object({
  quotaEntityId: types.string(),
  limitAmount: types.number(),
  currentSpend: types.number(),
  currentByokSpend: types.number(),
  includeByokInQuota: types.boolean(),
  refreshPeriod: types.string(),
  active: types.boolean(),
  archived: types.boolean(),
  alertThresholds: types.optional(z.array(types.number())),
  createdAt: types.number(),
  updatedAt: types.number(),
});

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