/*
 * 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 {
  BulkJobActionTemplates,
  BulkJobActionTemplates$inboundSchema,
} from "./bulkjobactiontemplates.js";
import {
  BulkJobConstraints,
  BulkJobConstraints$inboundSchema,
} from "./bulkjobconstraints.js";
import {
  BulkJobEmbedded,
  BulkJobEmbedded$inboundSchema,
} from "./bulkjobembedded.js";
import { BulkJobLinks, BulkJobLinks$inboundSchema } from "./bulkjoblinks.js";
import {
  BulkJobMetadata,
  BulkJobMetadata$inboundSchema,
} from "./bulkjobmetadata.js";
import { BulkJobStatus, BulkJobStatus$inboundSchema } from "./bulkjobstatus.js";

export type BulkJob = {
  /**
   * Id for job
   */
  id: string;
  /**
   * User provided reference ID for this job
   */
  externalJobId?: string | undefined;
  /**
   * User provided name for this job
   */
  name: string;
  /**
   * Job lifecycle states:
   *
   * @remarks
   * * OPEN - Job created and accepting documents
   * * UPLOAD_COMPLETE - All documents have been received, and processing has not yet started
   * * IN_PROGRESS - Documents are being processed (AI extraction)
   * * COMPLETE - The full e2e process is complete
   * * FAILED - System error prevented job execution
   * * CANCELED - User initiated request to cancel a job
   */
  status: BulkJobStatus;
  statusEnum: Array<string>;
  createdAt: Date;
  modifiedAt: Date;
  expiresAt: Date;
  /**
   * ISO 8601 duration for job validity
   */
  ttlPeriod?: string | undefined;
  /**
   * Contains detailed information about the BulkJob including presigned upload links, document IDs, etc
   */
  embedded?: BulkJobEmbedded | undefined;
  actionTemplates?: BulkJobActionTemplates | undefined;
  links?: BulkJobLinks | undefined;
  /**
   * Describes the limits of a bulk job, or an action associated with a bulk job
   */
  constraints?: BulkJobConstraints | undefined;
  /**
   * Properties about THIS request/response, not the job resource itself
   */
  metadata: BulkJobMetadata;
  message?: string | undefined;
};

/** @internal */
export const BulkJob$inboundSchema: z.ZodType<BulkJob, z.ZodTypeDef, unknown> =
  z.object({
    id: types.string(),
    external_job_id: types.optional(types.string()),
    name: types.string(),
    status: BulkJobStatus$inboundSchema,
    status_enum: z.array(types.string()),
    created_at: types.date(),
    modified_at: types.date(),
    expires_at: types.date(),
    ttl_period: types.optional(types.string()),
    _embedded: types.optional(BulkJobEmbedded$inboundSchema),
    _action_templates: types.optional(BulkJobActionTemplates$inboundSchema),
    _links: types.optional(BulkJobLinks$inboundSchema),
    constraints: types.optional(BulkJobConstraints$inboundSchema),
    metadata: BulkJobMetadata$inboundSchema,
    message: types.optional(types.string()),
  }).transform((v) => {
    return remap$(v, {
      "external_job_id": "externalJobId",
      "status_enum": "statusEnum",
      "created_at": "createdAt",
      "modified_at": "modifiedAt",
      "expires_at": "expiresAt",
      "ttl_period": "ttlPeriod",
      "_embedded": "embedded",
      "_action_templates": "actionTemplates",
      "_links": "links",
    });
  });

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