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

import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import * as types from "../../types/primitives.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ResponseMetadata,
  ResponseMetadata$inboundSchema,
} from "./responsemetadata.js";
import {
  WorkflowInstance,
  WorkflowInstance$inboundSchema,
} from "./workflowinstance.js";

export type WorkflowInstanceCollection = {
  /**
   * Array of workflow instances
   */
  data?: Array<WorkflowInstance> | undefined;
  /**
   * Control information and metadata for the response.
   */
  responseMetadata?: ResponseMetadata | undefined;
};

/** @internal */
export const WorkflowInstanceCollection$inboundSchema: z.ZodType<
  WorkflowInstanceCollection,
  z.ZodTypeDef,
  unknown
> = z.object({
  data: types.optional(z.array(WorkflowInstance$inboundSchema)),
  response_metadata: types.optional(ResponseMetadata$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "response_metadata": "responseMetadata",
  });
});

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