/*
 * 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 "./sdkvalidationerror.js";
import { UserEvent, UserEvent$inboundSchema } from "./userevent.js";

export type ListUserEventsRequest = {
  /**
   * Maximum number of items which may be returned.
   */
  limit?: number | undefined;
  /**
   * Timestamp to only include items created since then.
   */
  since?: string | undefined;
  /**
   * Timestamp to only include items created until then.
   */
  until?: string | undefined;
  /**
   * Comma-delimited list of event "types" to filter the results by.
   */
  types?: string | undefined;
  /**
   * Deprecated. Use `principalId` instead. If `principalId` and `userId` both exist, `principalId` will be used.
   */
  userId?: string | undefined;
  /**
   * When retrieving events for a Team, the `principalId` parameter may be specified to filter events generated by a specific principal.
   */
  principalId?: string | undefined;
  /**
   * Comma-delimited list of project IDs to filter the results by.
   */
  projectIds?: string | undefined;
  /**
   * When set to `true`, the response will include the `payload` field for each event.
   */
  withPayload?: 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;
};

/**
 * Successful response.
 */
export type ListUserEventsResponseBody = {
  /**
   * Array of events generated by the User.
   */
  events: Array<UserEvent>;
};

/** @internal */
export type ListUserEventsRequest$Outbound = {
  limit?: number | undefined;
  since?: string | undefined;
  until?: string | undefined;
  types?: string | undefined;
  userId?: string | undefined;
  principalId?: string | undefined;
  projectIds?: string | undefined;
  withPayload?: string | undefined;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const ListUserEventsRequest$outboundSchema: z.ZodType<
  ListUserEventsRequest$Outbound,
  z.ZodTypeDef,
  ListUserEventsRequest
> = z.object({
  limit: z.number().optional(),
  since: z.string().optional(),
  until: z.string().optional(),
  types: z.string().optional(),
  userId: z.string().optional(),
  principalId: z.string().optional(),
  projectIds: z.string().optional(),
  withPayload: z.string().optional(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
});

export function listUserEventsRequestToJSON(
  listUserEventsRequest: ListUserEventsRequest,
): string {
  return JSON.stringify(
    ListUserEventsRequest$outboundSchema.parse(listUserEventsRequest),
  );
}

/** @internal */
export const ListUserEventsResponseBody$inboundSchema: z.ZodType<
  ListUserEventsResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  events: z.array(UserEvent$inboundSchema),
});

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