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

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 { ProcessStatus, ProcessStatus$inboundSchema } from "./processstatus.js";

export type Document = {
  id: string;
  libraryId: string;
  /**
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  hash: string | null;
  mimeType: string | null;
  extension: string | null;
  size: number | null;
  name: string;
  summary?: string | null | undefined;
  createdAt: Date;
  lastProcessedAt?: Date | null | undefined;
  numberOfPages?: number | null | undefined;
  processStatus: ProcessStatus;
  uploadedById: string | null;
  uploadedByType: string;
  /**
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  tokensProcessingMainContent?: number | null | undefined;
  /**
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  tokensProcessingSummary?: number | null | undefined;
  url?: string | null | undefined;
  attributes?: { [k: string]: any } | null | undefined;
  /**
   * If set, the document will be automatically deleted after this date.
   */
  expiresAt?: Date | null | undefined;
  /**
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  processingStatus: string;
  tokensProcessingTotal: number;
};

/** @internal */
export const Document$inboundSchema: z.ZodType<Document, unknown> = z.object({
  id: z.string(),
  library_id: z.string(),
  hash: z.nullable(z.string()),
  mime_type: z.nullable(z.string()),
  extension: z.nullable(z.string()),
  size: z.nullable(z.int()),
  name: z.string(),
  summary: z.nullable(z.string()).optional(),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  last_processed_at: z.nullable(
    z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  number_of_pages: z.nullable(z.int()).optional(),
  process_status: ProcessStatus$inboundSchema,
  uploaded_by_id: z.nullable(z.string()),
  uploaded_by_type: z.string(),
  tokens_processing_main_content: z.nullable(z.int()).optional(),
  tokens_processing_summary: z.nullable(z.int()).optional(),
  url: z.nullable(z.string()).optional(),
  attributes: z.nullable(z.record(z.string(), z.any())).optional(),
  expires_at: z.nullable(
    z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  processing_status: z.string(),
  tokens_processing_total: z.int(),
}).transform((v) => {
  return remap$(v, {
    "library_id": "libraryId",
    "mime_type": "mimeType",
    "created_at": "createdAt",
    "last_processed_at": "lastProcessedAt",
    "number_of_pages": "numberOfPages",
    "process_status": "processStatus",
    "uploaded_by_id": "uploadedById",
    "uploaded_by_type": "uploadedByType",
    "tokens_processing_main_content": "tokensProcessingMainContent",
    "tokens_processing_summary": "tokensProcessingSummary",
    "expires_at": "expiresAt",
    "processing_status": "processingStatus",
    "tokens_processing_total": "tokensProcessingTotal",
  });
});

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