/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 4e2617d53d6d
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { smartUnion } from "../../types/smartUnion.js";
import * as components from "../components/index.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * Filter by workflow status
 */
export type ListRunsV1WorkflowsRunsGetStatus =
  | components.WorkflowExecutionStatus
  | Array<components.WorkflowExecutionStatus>;

export type ListRunsV1WorkflowsRunsGetRequest = {
  /**
   * Filter by workflow name or id
   */
  workflowIdentifier?: string | null | undefined;
  /**
   * Search by workflow name, display name or id
   */
  search?: string | null | undefined;
  /**
   * Filter by workflow status
   */
  status?:
    | components.WorkflowExecutionStatus
    | Array<components.WorkflowExecutionStatus>
    | null
    | undefined;
  /**
   * Filter by user id. Use 'current' to filter by the authenticated user
   */
  userId?: string | null | undefined;
  /**
   * Number of items per page
   */
  pageSize?: number | undefined;
  /**
   * Token for the next page of results
   */
  nextPageToken?: string | null | undefined;
};

export type ListRunsV1WorkflowsRunsGetResponse = {
  result: components.WorkflowExecutionListResponse;
};

/** @internal */
export type ListRunsV1WorkflowsRunsGetStatus$Outbound = string | Array<string>;

/** @internal */
export const ListRunsV1WorkflowsRunsGetStatus$outboundSchema: z.ZodType<
  ListRunsV1WorkflowsRunsGetStatus$Outbound,
  ListRunsV1WorkflowsRunsGetStatus
> = smartUnion([
  components.WorkflowExecutionStatus$outboundSchema,
  z.array(components.WorkflowExecutionStatus$outboundSchema),
]);

export function listRunsV1WorkflowsRunsGetStatusToJSON(
  listRunsV1WorkflowsRunsGetStatus: ListRunsV1WorkflowsRunsGetStatus,
): string {
  return JSON.stringify(
    ListRunsV1WorkflowsRunsGetStatus$outboundSchema.parse(
      listRunsV1WorkflowsRunsGetStatus,
    ),
  );
}

/** @internal */
export type ListRunsV1WorkflowsRunsGetRequest$Outbound = {
  workflow_identifier?: string | null | undefined;
  search?: string | null | undefined;
  status?: string | Array<string> | null | undefined;
  user_id?: string | null | undefined;
  page_size: number;
  next_page_token?: string | null | undefined;
};

/** @internal */
export const ListRunsV1WorkflowsRunsGetRequest$outboundSchema: z.ZodType<
  ListRunsV1WorkflowsRunsGetRequest$Outbound,
  ListRunsV1WorkflowsRunsGetRequest
> = z.object({
  workflowIdentifier: z.nullable(z.string()).optional(),
  search: z.nullable(z.string()).optional(),
  status: z.nullable(
    smartUnion([
      components.WorkflowExecutionStatus$outboundSchema,
      z.array(components.WorkflowExecutionStatus$outboundSchema),
    ]),
  ).optional(),
  userId: z.nullable(z.string()).optional(),
  pageSize: z.int().default(50),
  nextPageToken: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    workflowIdentifier: "workflow_identifier",
    userId: "user_id",
    pageSize: "page_size",
    nextPageToken: "next_page_token",
  });
});

export function listRunsV1WorkflowsRunsGetRequestToJSON(
  listRunsV1WorkflowsRunsGetRequest: ListRunsV1WorkflowsRunsGetRequest,
): string {
  return JSON.stringify(
    ListRunsV1WorkflowsRunsGetRequest$outboundSchema.parse(
      listRunsV1WorkflowsRunsGetRequest,
    ),
  );
}

/** @internal */
export const ListRunsV1WorkflowsRunsGetResponse$inboundSchema: z.ZodType<
  ListRunsV1WorkflowsRunsGetResponse,
  unknown
> = z.object({
  Result: components.WorkflowExecutionListResponse$inboundSchema,
}).transform((v) => {
  return remap$(v, {
    "Result": "result",
  });
});

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