/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  DownloadableFileRead,
  DownloadableFileRead$inboundSchema,
} from "./downloadablefileread.js";
import {
  OrganizationAvatarFileRead,
  OrganizationAvatarFileRead$inboundSchema,
} from "./organizationavatarfileread.js";
import {
  ProductMediaFileRead,
  ProductMediaFileRead$inboundSchema,
} from "./productmediafileread.js";
import {
  SupportCaseAttachmentFileRead,
  SupportCaseAttachmentFileRead$inboundSchema,
} from "./supportcaseattachmentfileread.js";

export type FileRead =
  | DownloadableFileRead
  | OrganizationAvatarFileRead
  | ProductMediaFileRead
  | SupportCaseAttachmentFileRead;

/** @internal */
export const FileRead$inboundSchema: z.ZodMiniType<FileRead, unknown> = z.union(
  [
    DownloadableFileRead$inboundSchema,
    OrganizationAvatarFileRead$inboundSchema,
    ProductMediaFileRead$inboundSchema,
    SupportCaseAttachmentFileRead$inboundSchema,
  ],
);

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