/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { BatchError, BatchError$inboundSchema } from "./batcherror.js";
import {
  BatchJobStatus,
  BatchJobStatus$inboundSchema,
} from "./batchjobstatus.js";

export const BatchJobOutObject = {
  Batch: "batch",
} as const;
export type BatchJobOutObject = ClosedEnum<typeof BatchJobOutObject>;

export type BatchJobOut = {
  id: string;
  object: BatchJobOutObject | undefined;
  inputFiles: Array<string>;
  metadata?: { [k: string]: any } | null | undefined;
  endpoint: string;
  model?: string | null | undefined;
  agentId?: string | null | undefined;
  outputFile?: string | null | undefined;
  errorFile?: string | null | undefined;
  errors: Array<BatchError>;
  outputs?: Array<{ [k: string]: any }> | null | undefined;
  status: BatchJobStatus;
  createdAt: number;
  totalRequests: number;
  completedRequests: number;
  succeededRequests: number;
  failedRequests: number;
  startedAt?: number | null | undefined;
  completedAt?: number | null | undefined;
};

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

/** @internal */
export const BatchJobOut$inboundSchema: z.ZodType<
  BatchJobOut,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  object: BatchJobOutObject$inboundSchema.default("batch"),
  input_files: z.array(z.string()),
  metadata: z.nullable(z.record(z.any())).optional(),
  endpoint: z.string(),
  model: z.nullable(z.string()).optional(),
  agent_id: z.nullable(z.string()).optional(),
  output_file: z.nullable(z.string()).optional(),
  error_file: z.nullable(z.string()).optional(),
  errors: z.array(BatchError$inboundSchema),
  outputs: z.nullable(z.array(z.record(z.any()))).optional(),
  status: BatchJobStatus$inboundSchema,
  created_at: z.number().int(),
  total_requests: z.number().int(),
  completed_requests: z.number().int(),
  succeeded_requests: z.number().int(),
  failed_requests: z.number().int(),
  started_at: z.nullable(z.number().int()).optional(),
  completed_at: z.nullable(z.number().int()).optional(),
}).transform((v) => {
  return remap$(v, {
    "input_files": "inputFiles",
    "agent_id": "agentId",
    "output_file": "outputFile",
    "error_file": "errorFile",
    "created_at": "createdAt",
    "total_requests": "totalRequests",
    "completed_requests": "completedRequests",
    "succeeded_requests": "succeededRequests",
    "failed_requests": "failedRequests",
    "started_at": "startedAt",
    "completed_at": "completedAt",
  });
});

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