/*
 * 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 { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type DocumentOut = {
  id: string;
  libraryId: string;
  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;
  uploadedById: string | null;
  uploadedByType: string;
  tokensProcessingMainContent?: number | null | undefined;
  tokensProcessingSummary?: number | null | undefined;
  url?: string | null | undefined;
  attributes?: { [k: string]: any } | null | undefined;
  processingStatus: string;
  tokensProcessingTotal: number;
};

/** @internal */
export const DocumentOut$inboundSchema: z.ZodType<
  DocumentOut,
  z.ZodTypeDef,
  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.number().int()),
  name: z.string(),
  summary: z.nullable(z.string()).optional(),
  created_at: z.string().datetime({ offset: true }).transform(v => new Date(v)),
  last_processed_at: z.nullable(
    z.string().datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  number_of_pages: z.nullable(z.number().int()).optional(),
  uploaded_by_id: z.nullable(z.string()),
  uploaded_by_type: z.string(),
  tokens_processing_main_content: z.nullable(z.number().int()).optional(),
  tokens_processing_summary: z.nullable(z.number().int()).optional(),
  url: z.nullable(z.string()).optional(),
  attributes: z.nullable(z.record(z.any())).optional(),
  processing_status: z.string(),
  tokens_processing_total: z.number().int(),
}).transform((v) => {
  return remap$(v, {
    "library_id": "libraryId",
    "mime_type": "mimeType",
    "created_at": "createdAt",
    "last_processed_at": "lastProcessedAt",
    "number_of_pages": "numberOfPages",
    "uploaded_by_id": "uploadedById",
    "uploaded_by_type": "uploadedByType",
    "tokens_processing_main_content": "tokensProcessingMainContent",
    "tokens_processing_summary": "tokensProcessingSummary",
    "processing_status": "processingStatus",
    "tokens_processing_total": "tokensProcessingTotal",
  });
});

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