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

import * as z from "zod";
import { remap as remap$ } from "../../../lib/primitives.js";

export type PerformSearchSearchErrors = {
  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 PerformSearchUnauthorizedData = {
  errors?: Array<PerformSearchSearchErrors> | 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 PerformSearchUnauthorized extends Error {
  errors?: Array<PerformSearchSearchErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: PerformSearchUnauthorizedData) {
    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 = "PerformSearchUnauthorized";
  }
}

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

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type PerformSearchBadRequestData = {
  errors?: Array<PerformSearchErrors> | 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 PerformSearchBadRequest extends Error {
  errors?: Array<PerformSearchErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: PerformSearchBadRequestData) {
    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 = "PerformSearchBadRequest";
  }
}

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

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

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

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

    return new PerformSearchUnauthorized(remapped);
  });

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

/** @internal */
export const PerformSearchUnauthorized$outboundSchema: z.ZodType<
  PerformSearchUnauthorized$Outbound,
  z.ZodTypeDef,
  PerformSearchUnauthorized
> = z.instanceof(PerformSearchUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => PerformSearchSearchErrors$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 PerformSearchUnauthorized$ {
  /** @deprecated use `PerformSearchUnauthorized$inboundSchema` instead. */
  export const inboundSchema = PerformSearchUnauthorized$inboundSchema;
  /** @deprecated use `PerformSearchUnauthorized$outboundSchema` instead. */
  export const outboundSchema = PerformSearchUnauthorized$outboundSchema;
  /** @deprecated use `PerformSearchUnauthorized$Outbound` instead. */
  export type Outbound = PerformSearchUnauthorized$Outbound;
}

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

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

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

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

    return new PerformSearchBadRequest(remapped);
  });

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

/** @internal */
export const PerformSearchBadRequest$outboundSchema: z.ZodType<
  PerformSearchBadRequest$Outbound,
  z.ZodTypeDef,
  PerformSearchBadRequest
> = z.instanceof(PerformSearchBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => PerformSearchErrors$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 PerformSearchBadRequest$ {
  /** @deprecated use `PerformSearchBadRequest$inboundSchema` instead. */
  export const inboundSchema = PerformSearchBadRequest$inboundSchema;
  /** @deprecated use `PerformSearchBadRequest$outboundSchema` instead. */
  export const outboundSchema = PerformSearchBadRequest$outboundSchema;
  /** @deprecated use `PerformSearchBadRequest$Outbound` instead. */
  export type Outbound = PerformSearchBadRequest$Outbound;
}
