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

import * as z from "zod/v4-mini";
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 S3DownloadURL = {
  url: string;
  headers?: { [k: string]: string } | undefined;
  expiresAt: Date;
};

/** @internal */
export const S3DownloadURL$inboundSchema: z.ZodMiniType<
  S3DownloadURL,
  unknown
> = z.pipe(
  z.object({
    url: z.string(),
    headers: z.optional(z.record(z.string(), z.string())),
    expires_at: z.pipe(
      z.iso.datetime({ offset: true }),
      z.transform(v => new Date(v)),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      "expires_at": "expiresAt",
    });
  }),
);

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