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

import * as z from "zod/v3";
import {
  collectExtraKeys as collectExtraKeys$,
  safeParse,
} from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export const ByQueryParam1 = {
  Hour: "hour",
  Day: "day",
  Week: "week",
  Month: "month",
  Year: "year",
  Country: "country",
  DeviceType: "deviceType",
  Environment: "environment",
  RequestPath: "requestPath",
  ReferrerHostname: "referrerHostname",
  OsName: "osName",
  BrowserName: "browserName",
  Route: "route",
  UtmSource: "utmSource",
  UtmMedium: "utmMedium",
  UtmCampaign: "utmCampaign",
  UtmContent: "utmContent",
  UtmTerm: "utmTerm",
  EventName: "eventName",
  Flags: "flags",
  EventData: "eventData",
} as const;
export type ByQueryParam1 = ClosedEnum<typeof ByQueryParam1>;

export type QueryParamBy = ByQueryParam1 | string;

/**
 * Timestamp in milliseconds, or a valid Date string.
 *
 * @remarks
 *
 * Selects data from (including) this date and time.
 * Will be adjusted according to the desired time granularity.
 */
export type QueryParamSince = number | string;

/**
 * Timestamp in milliseconds, or a valid Date string.
 *
 * @remarks
 *
 * Selects data until (including) this date.
 * Will be adjusted according to the desired time granularity.
 */
export type QueryParamUntil = number | string;

export type AggregateEventsRequest = {
  /**
   * The project identifier or the project name
   */
  projectId: string;
  /**
   * Up to two dimensions used to break down results.
   *
   * @remarks
   *
   * At most one time granularity is allowed: hour, day, week, month, year.
   *
   * Other dimensions: country, deviceType, environment, requestPath, referrerHostname, osName, browserName, route, utmSource, utmMedium, utmCampaign, utmContent, utmTerm, eventName.
   *
   * JSON dimensions: flags, eventData. Used bare, they break down results by key, for example flags returns one group per flag name. With a key, they break down results by that key's value, for example eventData/plan. Wrap keys containing characters other than letters, digits, and underscores in single quotes, for example flags/'my-flag'.
   */
  by: Array<ByQueryParam1 | string>;
  /**
   * Timestamp in milliseconds, or a valid Date string.
   *
   * @remarks
   *
   * Selects data from (including) this date and time.
   * Will be adjusted according to the desired time granularity.
   */
  since: number | string;
  /**
   * Timestamp in milliseconds, or a valid Date string.
   *
   * @remarks
   *
   * Selects data until (including) this date.
   * Will be adjusted according to the desired time granularity.
   */
  until: number | string;
  /**
   * Number of distinct results, default to 10. Other results are grouped into "Others" group.
   */
  limit?: number | undefined;
  /**
   * OData-compliant filter. Encode the value when sending it in a URL.
   *
   * @remarks
   *
   * Allows filtering on one or multiple dimensions. By default, filters for production environment only.
   *
   * Supported dimensions: country, deviceType, environment, requestPath, referrerHostname, osName, browserName, route, utmSource, utmMedium, utmCampaign, utmContent, utmTerm, eventName.
   *
   * JSON dimensions filtered by key: flags/<name>, eventData/<property>, for example eventData/plan eq 'pro'. Wrap keys containing characters other than letters, digits, and underscores in single quotes, for example flags/'my-flag' eq 'true'.
   *
   * Supported operations include eq, ne, in, and logical operators and, or, not with parentheses. Functions such as startswith are supported by the OData parser.
   */
  filter?: string | undefined;
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
};

export const AggregateEventsGroupBy2 = {
  BrowserName: "browserName",
  Country: "country",
  DeviceType: "deviceType",
  Environment: "environment",
  EventData: "eventData",
  EventName: "eventName",
  Flags: "flags",
  OsName: "osName",
  ReferrerHostname: "referrerHostname",
  RequestPath: "requestPath",
  Route: "route",
  UtmCampaign: "utmCampaign",
  UtmContent: "utmContent",
  UtmMedium: "utmMedium",
  UtmSource: "utmSource",
  UtmTerm: "utmTerm",
} as const;
export type AggregateEventsGroupBy2 = ClosedEnum<
  typeof AggregateEventsGroupBy2
>;

export type AggregateEventsGroupBy = string | AggregateEventsGroupBy2;

export type AggregateEventsQuery = {
  since: string;
  until: string;
  groupBy?: Array<string | AggregateEventsGroupBy2> | undefined;
  filter?: string | undefined;
  limit: number;
};

export type AggregateEventsData2 = {
  projectId: string;
  country: string;
  deviceType: string;
  environment: string;
  requestPath: string;
  referrerHostname: string;
  osName: string;
  browserName: string;
  route: string;
  utmSource: string;
  utmMedium: string;
  utmCampaign: string;
  utmContent: string;
  utmTerm: string;
  flags: string;
  errorMessage: string;
  entryRevalidateSeconds: string;
  projectName: string;
  deploymentId: string;
  pathType: string;
  pathTypeVariant: string;
  requestHostname: string;
  requestResolvedIp: string;
  requestMethod: string;
  requestExtension: string;
  requestId: string;
  requestApi: string;
  referrerUrl: string;
  serverActionName: string;
  httpStatus: string;
  errorCode: string;
  source: string;
  edgeType: string;
  reason: string;
  edgeNetworkRegion: string;
  functionRegion: string;
  imageTransformationRegion: string;
  dataCacheRegion: string;
  cause: string;
  runtime: string;
  provider: string;
  isrCacheRegion: string;
  isrAction: string;
  cacheResult: string;
  cacheOperation: string;
  cacheHostname: string;
  cachePath: string;
  cacheHitState: string;
  cacheHitLevel: string;
  cacheApi: string;
  cacheReason: string;
  pprState: string;
  clientIp: string;
  clientIpCountry: string;
  clientUserAgent: string;
  httpAccept: string;
  clientJa4Digest: string;
  asnId: string;
  asnName: string;
  botName: string;
  botCategory: string;
  botCategoryLegacy: string;
  botVerified: string;
  botCheckResult: string;
  deepAnalysisCheck: string;
  wafAction: string;
  wafRuleId: string;
  ruleCategory: string;
  skewProtection: string;
  functionStartType: string;
  functionDispatcher: string;
  isAdditionalRequest: string;
  originHostname: string;
  originPath: string;
  originRoute: string;
  fetchType: string;
  fetchIndex: string;
  imageSource: string;
  sourceImage: string;
  sourceImagePathname: string;
  sourceImageHostname: string;
  sourceImageHash: string;
  optimizedQuality: string;
  optimizedWidthPixels: string;
  optimizedFormatMimeType: string;
  vdcOperationOrigin: string;
  entryName: string;
  entryId: string;
  entryItemId: string;
  tagName: string;
  cacheTags: string;
  storeId: string;
  storeName: string;
  blobOperationType: string;
  blobOperationLevel: string;
  visitorId: string;
  eventName: string;
  attributionTarget: string;
  attributionEventName: string;
  metricName: string;
  attributes: string;
  flagKey: string;
  flagVariant: string;
  flagEvaluationReason: string;
  flagClientName: string;
  sdkKeyId: string;
  sdkKeyEnvironment: string;
  reportingProjectId: string;
  reportingProjectName: string;
  eventData: string;
  middlewareAction: string;
  middlewareActionTarget: string;
  aiModel: string;
  aiGatewayModelId: string;
  aiProvider: string;
  aiModelType: string;
  servedSpeed: string;
  virtualModelSlug: string;
  virtualModelKind: string;
  inferenceEndpointSlug: string;
  inferenceScope: string;
  inferenceGeoRegion: string;
  inferenceProviderRegion: string;
  requestedInferenceRegion: string;
  costCurrency: string;
  marketCostCurrency: string;
  cachedInputTokensCurrency: string;
  cacheCreationInputTokensCurrency: string;
  cacheCreation1hInputTokensCurrency: string;
  surchargeCostCurrency: string;
  gatewayCostCurrency: string;
  keyId: string;
  keyName: string;
  authMethod: string;
  appName: string;
  codingAgent: string;
  isByok: string;
  spendAttribution: string;
  isPrivateModel: string;
  isStreaming: string;
  isRequestZdr: string;
  hipaaRequested: string;
  quotaRequested: string;
  quotaEntityId: string;
  quotaEntityType: string;
  videoResolution: string;
  videoAspectRatio: string;
  piiRedactionApplied: string;
  moderationApplied: string;
  queueName: string;
  consumerGroup: string;
  messageId: string;
  eventType: string;
  notificationUrl: string;
  queueRegion: string;
  sandboxSessionId: string;
  sandboxName: string;
  workflowRunId: string;
  workflowName: string;
  workflowStatus: string;
  stepRunId: string;
  workflowStepName: string;
  workflowEventType: string;
  region: string;
  specVersion: string;
  contentType: string;
  rewriteDestinationHostname: string;
  externalRewriteTargetHost: string;
  externalRewriteTargetPath: string;
  commitSha: string;
  reviewConclusion: string;
  pullRequestNumber: string;
  repositoryName: string;
  repositoryOwner: string;
  reviewStatus: string;
  pullRequestState: string;
  triggeringTag: string;
  redirectLocation: string;
  microfrontendsResponseReason: string;
  microfrontendsMatchedPath: string;
  microfrontendsDefaultAppDeploymentId: string;
  microfrontendsDefaultAppProjectId: string;
  service: string;
  isPrefetchRequest: string;
  spendReportGroupBy: string;
  spendReportDatePart: string;
  providerAttemptCanonicalSlug: string;
  providerAttemptCredentialType: string;
  providerAttemptSuccess: string;
  providerAttemptStatusCode: string;
  providerAttemptTimeout: string;
  providerAttemptIsFinal: string;
  providerAttemptNumber: string;
  providerAttemptTotalInRequest: string;
  generationId: string;
  sessionId: string;
  contentCaptureStatus: string;
  contentCaptureInputs: string;
  contentCaptureOutputs: string;
  transcriptStatus: string;
  transcriptInputs: string;
  transcriptOutputs: string;
  providerAttemptError: string;
  providerAttemptSafetyIdentifier: string;
  providerAttemptDevSafetyIdentifier: string;
  providerAttemptRegion: string;
  providerAttemptModelIndex: string;
  toolCallType: string;
  toolCallProvider: string;
  toolCallSuccess: string;
  toolCallErrorType: string;
  toolCallStatusCode: string;
  environmentId: string;
  billableRegion: string;
  direction: string;
  networkTenancy: string;
  trafficSource: string;
  networkId: string;
  privatelinkEndpointId: string;
  privatelinkDnsName: string;
  privatelinkIpAddress: string;
  additionalProperties?: { [k: string]: number | null } | undefined;
};

export type AggregateEventsData1 = {
  projectId?: string | undefined;
  country?: string | undefined;
  deviceType?: string | undefined;
  environment?: string | undefined;
  requestPath?: string | undefined;
  referrerHostname?: string | undefined;
  osName?: string | undefined;
  browserName?: string | undefined;
  route?: string | undefined;
  utmSource?: string | undefined;
  utmMedium?: string | undefined;
  utmCampaign?: string | undefined;
  utmContent?: string | undefined;
  utmTerm?: string | undefined;
  flags?: string | undefined;
  errorMessage?: string | undefined;
  entryRevalidateSeconds?: string | undefined;
  projectName?: string | undefined;
  deploymentId?: string | undefined;
  pathType?: string | undefined;
  pathTypeVariant?: string | undefined;
  requestHostname?: string | undefined;
  requestResolvedIp?: string | undefined;
  requestMethod?: string | undefined;
  requestExtension?: string | undefined;
  requestId?: string | undefined;
  requestApi?: string | undefined;
  referrerUrl?: string | undefined;
  serverActionName?: string | undefined;
  httpStatus?: string | undefined;
  errorCode?: string | undefined;
  source?: string | undefined;
  edgeType?: string | undefined;
  reason?: string | undefined;
  edgeNetworkRegion?: string | undefined;
  functionRegion?: string | undefined;
  imageTransformationRegion?: string | undefined;
  dataCacheRegion?: string | undefined;
  cause?: string | undefined;
  runtime?: string | undefined;
  provider?: string | undefined;
  isrCacheRegion?: string | undefined;
  isrAction?: string | undefined;
  cacheResult?: string | undefined;
  cacheOperation?: string | undefined;
  cacheHostname?: string | undefined;
  cachePath?: string | undefined;
  cacheHitState?: string | undefined;
  cacheHitLevel?: string | undefined;
  cacheApi?: string | undefined;
  cacheReason?: string | undefined;
  pprState?: string | undefined;
  clientIp?: string | undefined;
  clientIpCountry?: string | undefined;
  clientUserAgent?: string | undefined;
  httpAccept?: string | undefined;
  clientJa4Digest?: string | undefined;
  asnId?: string | undefined;
  asnName?: string | undefined;
  botName?: string | undefined;
  botCategory?: string | undefined;
  botCategoryLegacy?: string | undefined;
  botVerified?: string | undefined;
  botCheckResult?: string | undefined;
  deepAnalysisCheck?: string | undefined;
  wafAction?: string | undefined;
  wafRuleId?: string | undefined;
  ruleCategory?: string | undefined;
  skewProtection?: string | undefined;
  functionStartType?: string | undefined;
  functionDispatcher?: string | undefined;
  isAdditionalRequest?: string | undefined;
  originHostname?: string | undefined;
  originPath?: string | undefined;
  originRoute?: string | undefined;
  fetchType?: string | undefined;
  fetchIndex?: string | undefined;
  imageSource?: string | undefined;
  sourceImage?: string | undefined;
  sourceImagePathname?: string | undefined;
  sourceImageHostname?: string | undefined;
  sourceImageHash?: string | undefined;
  optimizedQuality?: string | undefined;
  optimizedWidthPixels?: string | undefined;
  optimizedFormatMimeType?: string | undefined;
  vdcOperationOrigin?: string | undefined;
  entryName?: string | undefined;
  entryId?: string | undefined;
  entryItemId?: string | undefined;
  tagName?: string | undefined;
  cacheTags?: string | undefined;
  storeId?: string | undefined;
  storeName?: string | undefined;
  blobOperationType?: string | undefined;
  blobOperationLevel?: string | undefined;
  visitorId?: string | undefined;
  eventName?: string | undefined;
  attributionTarget?: string | undefined;
  attributionEventName?: string | undefined;
  metricName?: string | undefined;
  attributes?: string | undefined;
  flagKey?: string | undefined;
  flagVariant?: string | undefined;
  flagEvaluationReason?: string | undefined;
  flagClientName?: string | undefined;
  sdkKeyId?: string | undefined;
  sdkKeyEnvironment?: string | undefined;
  reportingProjectId?: string | undefined;
  reportingProjectName?: string | undefined;
  eventData?: string | undefined;
  middlewareAction?: string | undefined;
  middlewareActionTarget?: string | undefined;
  aiModel?: string | undefined;
  aiGatewayModelId?: string | undefined;
  aiProvider?: string | undefined;
  aiModelType?: string | undefined;
  servedSpeed?: string | undefined;
  virtualModelSlug?: string | undefined;
  virtualModelKind?: string | undefined;
  inferenceEndpointSlug?: string | undefined;
  inferenceScope?: string | undefined;
  inferenceGeoRegion?: string | undefined;
  inferenceProviderRegion?: string | undefined;
  requestedInferenceRegion?: string | undefined;
  costCurrency?: string | undefined;
  marketCostCurrency?: string | undefined;
  cachedInputTokensCurrency?: string | undefined;
  cacheCreationInputTokensCurrency?: string | undefined;
  cacheCreation1hInputTokensCurrency?: string | undefined;
  surchargeCostCurrency?: string | undefined;
  gatewayCostCurrency?: string | undefined;
  keyId?: string | undefined;
  keyName?: string | undefined;
  authMethod?: string | undefined;
  appName?: string | undefined;
  codingAgent?: string | undefined;
  isByok?: string | undefined;
  spendAttribution?: string | undefined;
  isPrivateModel?: string | undefined;
  isStreaming?: string | undefined;
  isRequestZdr?: string | undefined;
  hipaaRequested?: string | undefined;
  quotaRequested?: string | undefined;
  quotaEntityId?: string | undefined;
  quotaEntityType?: string | undefined;
  videoResolution?: string | undefined;
  videoAspectRatio?: string | undefined;
  piiRedactionApplied?: string | undefined;
  moderationApplied?: string | undefined;
  queueName?: string | undefined;
  consumerGroup?: string | undefined;
  messageId?: string | undefined;
  eventType?: string | undefined;
  notificationUrl?: string | undefined;
  queueRegion?: string | undefined;
  sandboxSessionId?: string | undefined;
  sandboxName?: string | undefined;
  workflowRunId?: string | undefined;
  workflowName?: string | undefined;
  workflowStatus?: string | undefined;
  stepRunId?: string | undefined;
  workflowStepName?: string | undefined;
  workflowEventType?: string | undefined;
  region?: string | undefined;
  specVersion?: string | undefined;
  contentType?: string | undefined;
  rewriteDestinationHostname?: string | undefined;
  externalRewriteTargetHost?: string | undefined;
  externalRewriteTargetPath?: string | undefined;
  commitSha?: string | undefined;
  reviewConclusion?: string | undefined;
  pullRequestNumber?: string | undefined;
  repositoryName?: string | undefined;
  repositoryOwner?: string | undefined;
  reviewStatus?: string | undefined;
  pullRequestState?: string | undefined;
  triggeringTag?: string | undefined;
  redirectLocation?: string | undefined;
  microfrontendsResponseReason?: string | undefined;
  microfrontendsMatchedPath?: string | undefined;
  microfrontendsDefaultAppDeploymentId?: string | undefined;
  microfrontendsDefaultAppProjectId?: string | undefined;
  service?: string | undefined;
  isPrefetchRequest?: string | undefined;
  spendReportGroupBy?: string | undefined;
  spendReportDatePart?: string | undefined;
  providerAttemptCanonicalSlug?: string | undefined;
  providerAttemptCredentialType?: string | undefined;
  providerAttemptSuccess?: string | undefined;
  providerAttemptStatusCode?: string | undefined;
  providerAttemptTimeout?: string | undefined;
  providerAttemptIsFinal?: string | undefined;
  providerAttemptNumber?: string | undefined;
  providerAttemptTotalInRequest?: string | undefined;
  generationId?: string | undefined;
  sessionId?: string | undefined;
  contentCaptureStatus?: string | undefined;
  contentCaptureInputs?: string | undefined;
  contentCaptureOutputs?: string | undefined;
  transcriptStatus?: string | undefined;
  transcriptInputs?: string | undefined;
  transcriptOutputs?: string | undefined;
  providerAttemptError?: string | undefined;
  providerAttemptSafetyIdentifier?: string | undefined;
  providerAttemptDevSafetyIdentifier?: string | undefined;
  providerAttemptRegion?: string | undefined;
  providerAttemptModelIndex?: string | undefined;
  toolCallType?: string | undefined;
  toolCallProvider?: string | undefined;
  toolCallSuccess?: string | undefined;
  toolCallErrorType?: string | undefined;
  toolCallStatusCode?: string | undefined;
  environmentId?: string | undefined;
  billableRegion?: string | undefined;
  direction?: string | undefined;
  networkTenancy?: string | undefined;
  trafficSource?: string | undefined;
  networkId?: string | undefined;
  privatelinkEndpointId?: string | undefined;
  privatelinkDnsName?: string | undefined;
  privatelinkIpAddress?: string | undefined;
  timestamp: Date;
};

export type AggregateEventsData =
  | Array<AggregateEventsData1>
  | Array<AggregateEventsData2>;

export type AggregateEventsResponseBody = {
  version: number;
  query: AggregateEventsQuery;
  data: Array<AggregateEventsData1> | Array<AggregateEventsData2>;
};

/** @internal */
export const ByQueryParam1$outboundSchema: z.ZodNativeEnum<
  typeof ByQueryParam1
> = z.nativeEnum(ByQueryParam1);

/** @internal */
export type QueryParamBy$Outbound = string | string;

/** @internal */
export const QueryParamBy$outboundSchema: z.ZodType<
  QueryParamBy$Outbound,
  z.ZodTypeDef,
  QueryParamBy
> = smartUnion([ByQueryParam1$outboundSchema, z.string()]);

export function queryParamByToJSON(queryParamBy: QueryParamBy): string {
  return JSON.stringify(QueryParamBy$outboundSchema.parse(queryParamBy));
}

/** @internal */
export type QueryParamSince$Outbound = number | string;

/** @internal */
export const QueryParamSince$outboundSchema: z.ZodType<
  QueryParamSince$Outbound,
  z.ZodTypeDef,
  QueryParamSince
> = smartUnion([z.number(), z.string()]);

export function queryParamSinceToJSON(
  queryParamSince: QueryParamSince,
): string {
  return JSON.stringify(QueryParamSince$outboundSchema.parse(queryParamSince));
}

/** @internal */
export type QueryParamUntil$Outbound = number | string;

/** @internal */
export const QueryParamUntil$outboundSchema: z.ZodType<
  QueryParamUntil$Outbound,
  z.ZodTypeDef,
  QueryParamUntil
> = smartUnion([z.number(), z.string()]);

export function queryParamUntilToJSON(
  queryParamUntil: QueryParamUntil,
): string {
  return JSON.stringify(QueryParamUntil$outboundSchema.parse(queryParamUntil));
}

/** @internal */
export type AggregateEventsRequest$Outbound = {
  projectId: string;
  by: Array<string | string>;
  since: number | string;
  until: number | string;
  limit: number;
  filter?: string | undefined;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const AggregateEventsRequest$outboundSchema: z.ZodType<
  AggregateEventsRequest$Outbound,
  z.ZodTypeDef,
  AggregateEventsRequest
> = z.object({
  projectId: z.string(),
  by: z.array(smartUnion([ByQueryParam1$outboundSchema, z.string()])),
  since: smartUnion([z.number(), z.string()]),
  until: smartUnion([z.number(), z.string()]),
  limit: z.number().int().default(10),
  filter: z.string().optional(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
});

export function aggregateEventsRequestToJSON(
  aggregateEventsRequest: AggregateEventsRequest,
): string {
  return JSON.stringify(
    AggregateEventsRequest$outboundSchema.parse(aggregateEventsRequest),
  );
}

/** @internal */
export const AggregateEventsGroupBy2$inboundSchema: z.ZodNativeEnum<
  typeof AggregateEventsGroupBy2
> = z.nativeEnum(AggregateEventsGroupBy2);

/** @internal */
export const AggregateEventsGroupBy$inboundSchema: z.ZodType<
  AggregateEventsGroupBy,
  z.ZodTypeDef,
  unknown
> = smartUnion([types.string(), AggregateEventsGroupBy2$inboundSchema]);

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

/** @internal */
export const AggregateEventsQuery$inboundSchema: z.ZodType<
  AggregateEventsQuery,
  z.ZodTypeDef,
  unknown
> = z.object({
  since: types.string(),
  until: types.string(),
  groupBy: types.optional(
    z.array(
      smartUnion([types.string(), AggregateEventsGroupBy2$inboundSchema]),
    ),
  ),
  filter: types.optional(types.string()),
  limit: types.number(),
});

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

/** @internal */
export const AggregateEventsData2$inboundSchema: z.ZodType<
  AggregateEventsData2,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    projectId: types.string(),
    country: types.string(),
    deviceType: types.string(),
    environment: types.string(),
    requestPath: types.string(),
    referrerHostname: types.string(),
    osName: types.string(),
    browserName: types.string(),
    route: types.string(),
    utmSource: types.string(),
    utmMedium: types.string(),
    utmCampaign: types.string(),
    utmContent: types.string(),
    utmTerm: types.string(),
    flags: types.string(),
    errorMessage: types.string(),
    entryRevalidateSeconds: types.string(),
    projectName: types.string(),
    deploymentId: types.string(),
    pathType: types.string(),
    pathTypeVariant: types.string(),
    requestHostname: types.string(),
    requestResolvedIp: types.string(),
    requestMethod: types.string(),
    requestExtension: types.string(),
    requestId: types.string(),
    requestApi: types.string(),
    referrerUrl: types.string(),
    serverActionName: types.string(),
    httpStatus: types.string(),
    errorCode: types.string(),
    source: types.string(),
    edgeType: types.string(),
    reason: types.string(),
    edgeNetworkRegion: types.string(),
    functionRegion: types.string(),
    imageTransformationRegion: types.string(),
    dataCacheRegion: types.string(),
    cause: types.string(),
    runtime: types.string(),
    provider: types.string(),
    isrCacheRegion: types.string(),
    isrAction: types.string(),
    cacheResult: types.string(),
    cacheOperation: types.string(),
    cacheHostname: types.string(),
    cachePath: types.string(),
    cacheHitState: types.string(),
    cacheHitLevel: types.string(),
    cacheApi: types.string(),
    cacheReason: types.string(),
    pprState: types.string(),
    clientIp: types.string(),
    clientIpCountry: types.string(),
    clientUserAgent: types.string(),
    httpAccept: types.string(),
    clientJa4Digest: types.string(),
    asnId: types.string(),
    asnName: types.string(),
    botName: types.string(),
    botCategory: types.string(),
    botCategoryLegacy: types.string(),
    botVerified: types.string(),
    botCheckResult: types.string(),
    deepAnalysisCheck: types.string(),
    wafAction: types.string(),
    wafRuleId: types.string(),
    ruleCategory: types.string(),
    skewProtection: types.string(),
    functionStartType: types.string(),
    functionDispatcher: types.string(),
    isAdditionalRequest: types.string(),
    originHostname: types.string(),
    originPath: types.string(),
    originRoute: types.string(),
    fetchType: types.string(),
    fetchIndex: types.string(),
    imageSource: types.string(),
    sourceImage: types.string(),
    sourceImagePathname: types.string(),
    sourceImageHostname: types.string(),
    sourceImageHash: types.string(),
    optimizedQuality: types.string(),
    optimizedWidthPixels: types.string(),
    optimizedFormatMimeType: types.string(),
    vdcOperationOrigin: types.string(),
    entryName: types.string(),
    entryId: types.string(),
    entryItemId: types.string(),
    tagName: types.string(),
    cacheTags: types.string(),
    storeId: types.string(),
    storeName: types.string(),
    blobOperationType: types.string(),
    blobOperationLevel: types.string(),
    visitorId: types.string(),
    eventName: types.string(),
    attributionTarget: types.string(),
    attributionEventName: types.string(),
    metricName: types.string(),
    attributes: types.string(),
    flagKey: types.string(),
    flagVariant: types.string(),
    flagEvaluationReason: types.string(),
    flagClientName: types.string(),
    sdkKeyId: types.string(),
    sdkKeyEnvironment: types.string(),
    reportingProjectId: types.string(),
    reportingProjectName: types.string(),
    eventData: types.string(),
    middlewareAction: types.string(),
    middlewareActionTarget: types.string(),
    aiModel: types.string(),
    aiGatewayModelId: types.string(),
    aiProvider: types.string(),
    aiModelType: types.string(),
    servedSpeed: types.string(),
    virtualModelSlug: types.string(),
    virtualModelKind: types.string(),
    inferenceEndpointSlug: types.string(),
    inferenceScope: types.string(),
    inferenceGeoRegion: types.string(),
    inferenceProviderRegion: types.string(),
    requestedInferenceRegion: types.string(),
    costCurrency: types.string(),
    marketCostCurrency: types.string(),
    cachedInputTokensCurrency: types.string(),
    cacheCreationInputTokensCurrency: types.string(),
    cacheCreation1hInputTokensCurrency: types.string(),
    surchargeCostCurrency: types.string(),
    gatewayCostCurrency: types.string(),
    keyId: types.string(),
    keyName: types.string(),
    authMethod: types.string(),
    appName: types.string(),
    codingAgent: types.string(),
    isByok: types.string(),
    spendAttribution: types.string(),
    isPrivateModel: types.string(),
    isStreaming: types.string(),
    isRequestZdr: types.string(),
    hipaaRequested: types.string(),
    quotaRequested: types.string(),
    quotaEntityId: types.string(),
    quotaEntityType: types.string(),
    videoResolution: types.string(),
    videoAspectRatio: types.string(),
    piiRedactionApplied: types.string(),
    moderationApplied: types.string(),
    queueName: types.string(),
    consumerGroup: types.string(),
    messageId: types.string(),
    eventType: types.string(),
    notificationUrl: types.string(),
    queueRegion: types.string(),
    sandboxSessionId: types.string(),
    sandboxName: types.string(),
    workflowRunId: types.string(),
    workflowName: types.string(),
    workflowStatus: types.string(),
    stepRunId: types.string(),
    workflowStepName: types.string(),
    workflowEventType: types.string(),
    region: types.string(),
    specVersion: types.string(),
    contentType: types.string(),
    rewriteDestinationHostname: types.string(),
    externalRewriteTargetHost: types.string(),
    externalRewriteTargetPath: types.string(),
    commitSha: types.string(),
    reviewConclusion: types.string(),
    pullRequestNumber: types.string(),
    repositoryName: types.string(),
    repositoryOwner: types.string(),
    reviewStatus: types.string(),
    pullRequestState: types.string(),
    triggeringTag: types.string(),
    redirectLocation: types.string(),
    microfrontendsResponseReason: types.string(),
    microfrontendsMatchedPath: types.string(),
    microfrontendsDefaultAppDeploymentId: types.string(),
    microfrontendsDefaultAppProjectId: types.string(),
    service: types.string(),
    isPrefetchRequest: types.string(),
    spendReportGroupBy: types.string(),
    spendReportDatePart: types.string(),
    providerAttemptCanonicalSlug: types.string(),
    providerAttemptCredentialType: types.string(),
    providerAttemptSuccess: types.string(),
    providerAttemptStatusCode: types.string(),
    providerAttemptTimeout: types.string(),
    providerAttemptIsFinal: types.string(),
    providerAttemptNumber: types.string(),
    providerAttemptTotalInRequest: types.string(),
    generationId: types.string(),
    sessionId: types.string(),
    contentCaptureStatus: types.string(),
    contentCaptureInputs: types.string(),
    contentCaptureOutputs: types.string(),
    transcriptStatus: types.string(),
    transcriptInputs: types.string(),
    transcriptOutputs: types.string(),
    providerAttemptError: types.string(),
    providerAttemptSafetyIdentifier: types.string(),
    providerAttemptDevSafetyIdentifier: types.string(),
    providerAttemptRegion: types.string(),
    providerAttemptModelIndex: types.string(),
    toolCallType: types.string(),
    toolCallProvider: types.string(),
    toolCallSuccess: types.string(),
    toolCallErrorType: types.string(),
    toolCallStatusCode: types.string(),
    environmentId: types.string(),
    billableRegion: types.string(),
    direction: types.string(),
    networkTenancy: types.string(),
    trafficSource: types.string(),
    networkId: types.string(),
    privatelinkEndpointId: types.string(),
    privatelinkDnsName: types.string(),
    privatelinkIpAddress: types.string(),
  }).catchall(types.number()),
  "additionalProperties",
  true,
);

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

/** @internal */
export const AggregateEventsData1$inboundSchema: z.ZodType<
  AggregateEventsData1,
  z.ZodTypeDef,
  unknown
> = z.object({
  projectId: types.optional(types.string()),
  country: types.optional(types.string()),
  deviceType: types.optional(types.string()),
  environment: types.optional(types.string()),
  requestPath: types.optional(types.string()),
  referrerHostname: types.optional(types.string()),
  osName: types.optional(types.string()),
  browserName: types.optional(types.string()),
  route: types.optional(types.string()),
  utmSource: types.optional(types.string()),
  utmMedium: types.optional(types.string()),
  utmCampaign: types.optional(types.string()),
  utmContent: types.optional(types.string()),
  utmTerm: types.optional(types.string()),
  flags: types.optional(types.string()),
  errorMessage: types.optional(types.string()),
  entryRevalidateSeconds: types.optional(types.string()),
  projectName: types.optional(types.string()),
  deploymentId: types.optional(types.string()),
  pathType: types.optional(types.string()),
  pathTypeVariant: types.optional(types.string()),
  requestHostname: types.optional(types.string()),
  requestResolvedIp: types.optional(types.string()),
  requestMethod: types.optional(types.string()),
  requestExtension: types.optional(types.string()),
  requestId: types.optional(types.string()),
  requestApi: types.optional(types.string()),
  referrerUrl: types.optional(types.string()),
  serverActionName: types.optional(types.string()),
  httpStatus: types.optional(types.string()),
  errorCode: types.optional(types.string()),
  source: types.optional(types.string()),
  edgeType: types.optional(types.string()),
  reason: types.optional(types.string()),
  edgeNetworkRegion: types.optional(types.string()),
  functionRegion: types.optional(types.string()),
  imageTransformationRegion: types.optional(types.string()),
  dataCacheRegion: types.optional(types.string()),
  cause: types.optional(types.string()),
  runtime: types.optional(types.string()),
  provider: types.optional(types.string()),
  isrCacheRegion: types.optional(types.string()),
  isrAction: types.optional(types.string()),
  cacheResult: types.optional(types.string()),
  cacheOperation: types.optional(types.string()),
  cacheHostname: types.optional(types.string()),
  cachePath: types.optional(types.string()),
  cacheHitState: types.optional(types.string()),
  cacheHitLevel: types.optional(types.string()),
  cacheApi: types.optional(types.string()),
  cacheReason: types.optional(types.string()),
  pprState: types.optional(types.string()),
  clientIp: types.optional(types.string()),
  clientIpCountry: types.optional(types.string()),
  clientUserAgent: types.optional(types.string()),
  httpAccept: types.optional(types.string()),
  clientJa4Digest: types.optional(types.string()),
  asnId: types.optional(types.string()),
  asnName: types.optional(types.string()),
  botName: types.optional(types.string()),
  botCategory: types.optional(types.string()),
  botCategoryLegacy: types.optional(types.string()),
  botVerified: types.optional(types.string()),
  botCheckResult: types.optional(types.string()),
  deepAnalysisCheck: types.optional(types.string()),
  wafAction: types.optional(types.string()),
  wafRuleId: types.optional(types.string()),
  ruleCategory: types.optional(types.string()),
  skewProtection: types.optional(types.string()),
  functionStartType: types.optional(types.string()),
  functionDispatcher: types.optional(types.string()),
  isAdditionalRequest: types.optional(types.string()),
  originHostname: types.optional(types.string()),
  originPath: types.optional(types.string()),
  originRoute: types.optional(types.string()),
  fetchType: types.optional(types.string()),
  fetchIndex: types.optional(types.string()),
  imageSource: types.optional(types.string()),
  sourceImage: types.optional(types.string()),
  sourceImagePathname: types.optional(types.string()),
  sourceImageHostname: types.optional(types.string()),
  sourceImageHash: types.optional(types.string()),
  optimizedQuality: types.optional(types.string()),
  optimizedWidthPixels: types.optional(types.string()),
  optimizedFormatMimeType: types.optional(types.string()),
  vdcOperationOrigin: types.optional(types.string()),
  entryName: types.optional(types.string()),
  entryId: types.optional(types.string()),
  entryItemId: types.optional(types.string()),
  tagName: types.optional(types.string()),
  cacheTags: types.optional(types.string()),
  storeId: types.optional(types.string()),
  storeName: types.optional(types.string()),
  blobOperationType: types.optional(types.string()),
  blobOperationLevel: types.optional(types.string()),
  visitorId: types.optional(types.string()),
  eventName: types.optional(types.string()),
  attributionTarget: types.optional(types.string()),
  attributionEventName: types.optional(types.string()),
  metricName: types.optional(types.string()),
  attributes: types.optional(types.string()),
  flagKey: types.optional(types.string()),
  flagVariant: types.optional(types.string()),
  flagEvaluationReason: types.optional(types.string()),
  flagClientName: types.optional(types.string()),
  sdkKeyId: types.optional(types.string()),
  sdkKeyEnvironment: types.optional(types.string()),
  reportingProjectId: types.optional(types.string()),
  reportingProjectName: types.optional(types.string()),
  eventData: types.optional(types.string()),
  middlewareAction: types.optional(types.string()),
  middlewareActionTarget: types.optional(types.string()),
  aiModel: types.optional(types.string()),
  aiGatewayModelId: types.optional(types.string()),
  aiProvider: types.optional(types.string()),
  aiModelType: types.optional(types.string()),
  servedSpeed: types.optional(types.string()),
  virtualModelSlug: types.optional(types.string()),
  virtualModelKind: types.optional(types.string()),
  inferenceEndpointSlug: types.optional(types.string()),
  inferenceScope: types.optional(types.string()),
  inferenceGeoRegion: types.optional(types.string()),
  inferenceProviderRegion: types.optional(types.string()),
  requestedInferenceRegion: types.optional(types.string()),
  costCurrency: types.optional(types.string()),
  marketCostCurrency: types.optional(types.string()),
  cachedInputTokensCurrency: types.optional(types.string()),
  cacheCreationInputTokensCurrency: types.optional(types.string()),
  cacheCreation1hInputTokensCurrency: types.optional(types.string()),
  surchargeCostCurrency: types.optional(types.string()),
  gatewayCostCurrency: types.optional(types.string()),
  keyId: types.optional(types.string()),
  keyName: types.optional(types.string()),
  authMethod: types.optional(types.string()),
  appName: types.optional(types.string()),
  codingAgent: types.optional(types.string()),
  isByok: types.optional(types.string()),
  spendAttribution: types.optional(types.string()),
  isPrivateModel: types.optional(types.string()),
  isStreaming: types.optional(types.string()),
  isRequestZdr: types.optional(types.string()),
  hipaaRequested: types.optional(types.string()),
  quotaRequested: types.optional(types.string()),
  quotaEntityId: types.optional(types.string()),
  quotaEntityType: types.optional(types.string()),
  videoResolution: types.optional(types.string()),
  videoAspectRatio: types.optional(types.string()),
  piiRedactionApplied: types.optional(types.string()),
  moderationApplied: types.optional(types.string()),
  queueName: types.optional(types.string()),
  consumerGroup: types.optional(types.string()),
  messageId: types.optional(types.string()),
  eventType: types.optional(types.string()),
  notificationUrl: types.optional(types.string()),
  queueRegion: types.optional(types.string()),
  sandboxSessionId: types.optional(types.string()),
  sandboxName: types.optional(types.string()),
  workflowRunId: types.optional(types.string()),
  workflowName: types.optional(types.string()),
  workflowStatus: types.optional(types.string()),
  stepRunId: types.optional(types.string()),
  workflowStepName: types.optional(types.string()),
  workflowEventType: types.optional(types.string()),
  region: types.optional(types.string()),
  specVersion: types.optional(types.string()),
  contentType: types.optional(types.string()),
  rewriteDestinationHostname: types.optional(types.string()),
  externalRewriteTargetHost: types.optional(types.string()),
  externalRewriteTargetPath: types.optional(types.string()),
  commitSha: types.optional(types.string()),
  reviewConclusion: types.optional(types.string()),
  pullRequestNumber: types.optional(types.string()),
  repositoryName: types.optional(types.string()),
  repositoryOwner: types.optional(types.string()),
  reviewStatus: types.optional(types.string()),
  pullRequestState: types.optional(types.string()),
  triggeringTag: types.optional(types.string()),
  redirectLocation: types.optional(types.string()),
  microfrontendsResponseReason: types.optional(types.string()),
  microfrontendsMatchedPath: types.optional(types.string()),
  microfrontendsDefaultAppDeploymentId: types.optional(types.string()),
  microfrontendsDefaultAppProjectId: types.optional(types.string()),
  service: types.optional(types.string()),
  isPrefetchRequest: types.optional(types.string()),
  spendReportGroupBy: types.optional(types.string()),
  spendReportDatePart: types.optional(types.string()),
  providerAttemptCanonicalSlug: types.optional(types.string()),
  providerAttemptCredentialType: types.optional(types.string()),
  providerAttemptSuccess: types.optional(types.string()),
  providerAttemptStatusCode: types.optional(types.string()),
  providerAttemptTimeout: types.optional(types.string()),
  providerAttemptIsFinal: types.optional(types.string()),
  providerAttemptNumber: types.optional(types.string()),
  providerAttemptTotalInRequest: types.optional(types.string()),
  generationId: types.optional(types.string()),
  sessionId: types.optional(types.string()),
  contentCaptureStatus: types.optional(types.string()),
  contentCaptureInputs: types.optional(types.string()),
  contentCaptureOutputs: types.optional(types.string()),
  transcriptStatus: types.optional(types.string()),
  transcriptInputs: types.optional(types.string()),
  transcriptOutputs: types.optional(types.string()),
  providerAttemptError: types.optional(types.string()),
  providerAttemptSafetyIdentifier: types.optional(types.string()),
  providerAttemptDevSafetyIdentifier: types.optional(types.string()),
  providerAttemptRegion: types.optional(types.string()),
  providerAttemptModelIndex: types.optional(types.string()),
  toolCallType: types.optional(types.string()),
  toolCallProvider: types.optional(types.string()),
  toolCallSuccess: types.optional(types.string()),
  toolCallErrorType: types.optional(types.string()),
  toolCallStatusCode: types.optional(types.string()),
  environmentId: types.optional(types.string()),
  billableRegion: types.optional(types.string()),
  direction: types.optional(types.string()),
  networkTenancy: types.optional(types.string()),
  trafficSource: types.optional(types.string()),
  networkId: types.optional(types.string()),
  privatelinkEndpointId: types.optional(types.string()),
  privatelinkDnsName: types.optional(types.string()),
  privatelinkIpAddress: types.optional(types.string()),
  timestamp: types.date(),
});

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

/** @internal */
export const AggregateEventsData$inboundSchema: z.ZodType<
  AggregateEventsData,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.array(z.lazy(() => AggregateEventsData1$inboundSchema)),
  z.array(z.lazy(() => AggregateEventsData2$inboundSchema)),
]);

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

/** @internal */
export const AggregateEventsResponseBody$inboundSchema: z.ZodType<
  AggregateEventsResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  version: types.number(),
  query: z.lazy(() => AggregateEventsQuery$inboundSchema),
  data: smartUnion([
    z.array(z.lazy(() => AggregateEventsData1$inboundSchema)),
    z.array(z.lazy(() => AggregateEventsData2$inboundSchema)),
  ]),
});

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