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

import * as z from "zod";
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 PostMediaPosterRequest = {
  /**
   * the id of the library item to return the posters of.
   */
  ratingKey: number;
  /**
   * The URL of the image, if uploading a remote image
   */
  url?: string | undefined;
  /**
   * The contents of the image, if uploading a local file
   */
  requestBody?:
    | ReadableStream<Uint8Array>
    | Blob
    | ArrayBuffer
    | Uint8Array
    | undefined;
};

export type PostMediaPosterResponse = {
  /**
   * HTTP response content type for this operation
   */
  contentType: string;
  /**
   * HTTP response status code for this operation
   */
  statusCode: number;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse: Response;
};

/** @internal */
export const PostMediaPosterRequest$inboundSchema: z.ZodType<
  PostMediaPosterRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  ratingKey: z.number().int(),
  url: z.string().optional(),
  RequestBody: z.union([
    z.instanceof(ReadableStream<Uint8Array>),
    z.instanceof(Blob),
    z.instanceof(ArrayBuffer),
    z.instanceof(Uint8Array),
  ]).optional(),
}).transform((v) => {
  return remap$(v, {
    "RequestBody": "requestBody",
  });
});

/** @internal */
export type PostMediaPosterRequest$Outbound = {
  ratingKey: number;
  url?: string | undefined;
  RequestBody?:
    | ReadableStream<Uint8Array>
    | Blob
    | ArrayBuffer
    | Uint8Array
    | undefined;
};

/** @internal */
export const PostMediaPosterRequest$outboundSchema: z.ZodType<
  PostMediaPosterRequest$Outbound,
  z.ZodTypeDef,
  PostMediaPosterRequest
> = z.object({
  ratingKey: z.number().int(),
  url: z.string().optional(),
  requestBody: z.union([
    z.instanceof(ReadableStream<Uint8Array>),
    z.instanceof(Blob),
    z.instanceof(ArrayBuffer),
    z.instanceof(Uint8Array),
  ]).optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PostMediaPosterRequest$ {
  /** @deprecated use `PostMediaPosterRequest$inboundSchema` instead. */
  export const inboundSchema = PostMediaPosterRequest$inboundSchema;
  /** @deprecated use `PostMediaPosterRequest$outboundSchema` instead. */
  export const outboundSchema = PostMediaPosterRequest$outboundSchema;
  /** @deprecated use `PostMediaPosterRequest$Outbound` instead. */
  export type Outbound = PostMediaPosterRequest$Outbound;
}

export function postMediaPosterRequestToJSON(
  postMediaPosterRequest: PostMediaPosterRequest,
): string {
  return JSON.stringify(
    PostMediaPosterRequest$outboundSchema.parse(postMediaPosterRequest),
  );
}

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

/** @internal */
export const PostMediaPosterResponse$inboundSchema: z.ZodType<
  PostMediaPosterResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
  });
});

/** @internal */
export type PostMediaPosterResponse$Outbound = {
  ContentType: string;
  StatusCode: number;
  RawResponse: never;
};

/** @internal */
export const PostMediaPosterResponse$outboundSchema: z.ZodType<
  PostMediaPosterResponse$Outbound,
  z.ZodTypeDef,
  PostMediaPosterResponse
> = z.object({
  contentType: z.string(),
  statusCode: z.number().int(),
  rawResponse: z.instanceof(Response).transform(() => {
    throw new Error("Response cannot be serialized");
  }),
}).transform((v) => {
  return remap$(v, {
    contentType: "ContentType",
    statusCode: "StatusCode",
    rawResponse: "RawResponse",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PostMediaPosterResponse$ {
  /** @deprecated use `PostMediaPosterResponse$inboundSchema` instead. */
  export const inboundSchema = PostMediaPosterResponse$inboundSchema;
  /** @deprecated use `PostMediaPosterResponse$outboundSchema` instead. */
  export const outboundSchema = PostMediaPosterResponse$outboundSchema;
  /** @deprecated use `PostMediaPosterResponse$Outbound` instead. */
  export type Outbound = PostMediaPosterResponse$Outbound;
}

export function postMediaPosterResponseToJSON(
  postMediaPosterResponse: PostMediaPosterResponse,
): string {
  return JSON.stringify(
    PostMediaPosterResponse$outboundSchema.parse(postMediaPosterResponse),
  );
}

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