/*
 * 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 "./sdkvalidationerror.js";

export type PerformVoiceSearchSearchErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export type PerformVoiceSearchUnauthorizedData = {
  errors?: Array<PerformVoiceSearchSearchErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export class PerformVoiceSearchUnauthorized extends Error {
  errors?: Array<PerformVoiceSearchSearchErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

  /** The original data that was passed to this error instance. */
  data$: PerformVoiceSearchUnauthorizedData;

  constructor(err: PerformVoiceSearchUnauthorizedData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "PerformVoiceSearchUnauthorized";
  }
}

export type PerformVoiceSearchErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type PerformVoiceSearchBadRequestData = {
  errors?: Array<PerformVoiceSearchErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export class PerformVoiceSearchBadRequest extends Error {
  errors?: Array<PerformVoiceSearchErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

  /** The original data that was passed to this error instance. */
  data$: PerformVoiceSearchBadRequestData;

  constructor(err: PerformVoiceSearchBadRequestData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "PerformVoiceSearchBadRequest";
  }
}

/** @internal */
export const PerformVoiceSearchSearchErrors$inboundSchema: z.ZodType<
  PerformVoiceSearchSearchErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type PerformVoiceSearchSearchErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const PerformVoiceSearchSearchErrors$outboundSchema: z.ZodType<
  PerformVoiceSearchSearchErrors$Outbound,
  z.ZodTypeDef,
  PerformVoiceSearchSearchErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

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

export function performVoiceSearchSearchErrorsToJSON(
  performVoiceSearchSearchErrors: PerformVoiceSearchSearchErrors,
): string {
  return JSON.stringify(
    PerformVoiceSearchSearchErrors$outboundSchema.parse(
      performVoiceSearchSearchErrors,
    ),
  );
}

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

/** @internal */
export const PerformVoiceSearchUnauthorized$inboundSchema: z.ZodType<
  PerformVoiceSearchUnauthorized,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(z.lazy(() => PerformVoiceSearchSearchErrors$inboundSchema))
    .optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new PerformVoiceSearchUnauthorized(remapped);
  });

/** @internal */
export type PerformVoiceSearchUnauthorized$Outbound = {
  errors?: Array<PerformVoiceSearchSearchErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const PerformVoiceSearchUnauthorized$outboundSchema: z.ZodType<
  PerformVoiceSearchUnauthorized$Outbound,
  z.ZodTypeDef,
  PerformVoiceSearchUnauthorized
> = z.instanceof(PerformVoiceSearchUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(
        z.lazy(() => PerformVoiceSearchSearchErrors$outboundSchema),
      ).optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        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 PerformVoiceSearchUnauthorized$ {
  /** @deprecated use `PerformVoiceSearchUnauthorized$inboundSchema` instead. */
  export const inboundSchema = PerformVoiceSearchUnauthorized$inboundSchema;
  /** @deprecated use `PerformVoiceSearchUnauthorized$outboundSchema` instead. */
  export const outboundSchema = PerformVoiceSearchUnauthorized$outboundSchema;
  /** @deprecated use `PerformVoiceSearchUnauthorized$Outbound` instead. */
  export type Outbound = PerformVoiceSearchUnauthorized$Outbound;
}

/** @internal */
export const PerformVoiceSearchErrors$inboundSchema: z.ZodType<
  PerformVoiceSearchErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type PerformVoiceSearchErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const PerformVoiceSearchErrors$outboundSchema: z.ZodType<
  PerformVoiceSearchErrors$Outbound,
  z.ZodTypeDef,
  PerformVoiceSearchErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

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

export function performVoiceSearchErrorsToJSON(
  performVoiceSearchErrors: PerformVoiceSearchErrors,
): string {
  return JSON.stringify(
    PerformVoiceSearchErrors$outboundSchema.parse(performVoiceSearchErrors),
  );
}

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

/** @internal */
export const PerformVoiceSearchBadRequest$inboundSchema: z.ZodType<
  PerformVoiceSearchBadRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(z.lazy(() => PerformVoiceSearchErrors$inboundSchema))
    .optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new PerformVoiceSearchBadRequest(remapped);
  });

/** @internal */
export type PerformVoiceSearchBadRequest$Outbound = {
  errors?: Array<PerformVoiceSearchErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const PerformVoiceSearchBadRequest$outboundSchema: z.ZodType<
  PerformVoiceSearchBadRequest$Outbound,
  z.ZodTypeDef,
  PerformVoiceSearchBadRequest
> = z.instanceof(PerformVoiceSearchBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => PerformVoiceSearchErrors$outboundSchema))
        .optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        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 PerformVoiceSearchBadRequest$ {
  /** @deprecated use `PerformVoiceSearchBadRequest$inboundSchema` instead. */
  export const inboundSchema = PerformVoiceSearchBadRequest$inboundSchema;
  /** @deprecated use `PerformVoiceSearchBadRequest$outboundSchema` instead. */
  export const outboundSchema = PerformVoiceSearchBadRequest$outboundSchema;
  /** @deprecated use `PerformVoiceSearchBadRequest$Outbound` instead. */
  export type Outbound = PerformVoiceSearchBadRequest$Outbound;
}
