/*
 * 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 PerformSearchRequest = {
  /**
   * The query term
   */
  query: string;
  /**
   * This gives context to the search, and can result in re-ordering of search result hubs
   */
  sectionId?: number | undefined;
  /**
   * The number of items to return per hub
   */
  limit?: number | undefined;
};

export type PerformSearchResponse = {
  /**
   * 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 PerformSearchRequest$inboundSchema: z.ZodType<
  PerformSearchRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  query: z.string(),
  sectionId: z.number().optional(),
  limit: z.number().default(3),
});

/** @internal */
export type PerformSearchRequest$Outbound = {
  query: string;
  sectionId?: number | undefined;
  limit: number;
};

/** @internal */
export const PerformSearchRequest$outboundSchema: z.ZodType<
  PerformSearchRequest$Outbound,
  z.ZodTypeDef,
  PerformSearchRequest
> = z.object({
  query: z.string(),
  sectionId: z.number().optional(),
  limit: z.number().default(3),
});

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

export function performSearchRequestToJSON(
  performSearchRequest: PerformSearchRequest,
): string {
  return JSON.stringify(
    PerformSearchRequest$outboundSchema.parse(performSearchRequest),
  );
}

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

/** @internal */
export const PerformSearchResponse$inboundSchema: z.ZodType<
  PerformSearchResponse,
  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 PerformSearchResponse$Outbound = {
  ContentType: string;
  StatusCode: number;
  RawResponse: never;
};

/** @internal */
export const PerformSearchResponse$outboundSchema: z.ZodType<
  PerformSearchResponse$Outbound,
  z.ZodTypeDef,
  PerformSearchResponse
> = 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 PerformSearchResponse$ {
  /** @deprecated use `PerformSearchResponse$inboundSchema` instead. */
  export const inboundSchema = PerformSearchResponse$inboundSchema;
  /** @deprecated use `PerformSearchResponse$outboundSchema` instead. */
  export const outboundSchema = PerformSearchResponse$outboundSchema;
  /** @deprecated use `PerformSearchResponse$Outbound` instead. */
  export type Outbound = PerformSearchResponse$Outbound;
}

export function performSearchResponseToJSON(
  performSearchResponse: PerformSearchResponse,
): string {
  return JSON.stringify(
    PerformSearchResponse$outboundSchema.parse(performSearchResponse),
  );
}

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