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

import * as z from "zod";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ResponseMetadata,
  ResponseMetadata$inboundSchema,
  ResponseMetadata$Outbound,
  ResponseMetadata$outboundSchema,
} from "./responsemetadata.js";
import {
  WorkflowInstance,
  WorkflowInstance$inboundSchema,
  WorkflowInstance$Outbound,
  WorkflowInstance$outboundSchema,
} 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: z.array(WorkflowInstance$inboundSchema).optional(),
  response_metadata: ResponseMetadata$inboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    "response_metadata": "responseMetadata",
  });
});

/** @internal */
export type WorkflowInstanceCollection$Outbound = {
  data?: Array<WorkflowInstance$Outbound> | undefined;
  response_metadata?: ResponseMetadata$Outbound | undefined;
};

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

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace WorkflowInstanceCollection$ {
  /** @deprecated use `WorkflowInstanceCollection$inboundSchema` instead. */
  export const inboundSchema = WorkflowInstanceCollection$inboundSchema;
  /** @deprecated use `WorkflowInstanceCollection$outboundSchema` instead. */
  export const outboundSchema = WorkflowInstanceCollection$outboundSchema;
  /** @deprecated use `WorkflowInstanceCollection$Outbound` instead. */
  export type Outbound = WorkflowInstanceCollection$Outbound;
}

export function workflowInstanceCollectionToJSON(
  workflowInstanceCollection: WorkflowInstanceCollection,
): string {
  return JSON.stringify(
    WorkflowInstanceCollection$outboundSchema.parse(workflowInstanceCollection),
  );
}

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