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

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 { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { BatchError, BatchError$inboundSchema } from "./batcherror.js";
import {
  BatchJobStatus,
  BatchJobStatus$inboundSchema,
} from "./batchjobstatus.js";

export type BatchJob = {
  id: string;
  object: "batch";
  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 BatchJob$inboundSchema: z.ZodType<BatchJob, unknown> = z.object({
  id: z.string(),
  object: z.literal("batch").default("batch"),
  input_files: z.array(z.string()),
  metadata: z.nullable(z.record(z.string(), 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.string(), z.any()))).optional(),
  status: BatchJobStatus$inboundSchema,
  created_at: z.int(),
  total_requests: z.int(),
  completed_requests: z.int(),
  succeeded_requests: z.int(),
  failed_requests: z.int(),
  started_at: z.nullable(z.int()).optional(),
  completed_at: z.nullable(z.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 batchJobFromJSON(
  jsonString: string,
): SafeParseResult<BatchJob, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BatchJob$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BatchJob' from JSON`,
  );
}
