/*
 * 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 GetSearchAllLibrariesLibraryErrors = {
  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 GetSearchAllLibrariesUnauthorizedData = {
  errors?: Array<GetSearchAllLibrariesLibraryErrors> | 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 GetSearchAllLibrariesUnauthorized extends Error {
  errors?: Array<GetSearchAllLibrariesLibraryErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

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

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

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

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

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

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

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

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

export function getSearchAllLibrariesLibraryErrorsToJSON(
  getSearchAllLibrariesLibraryErrors: GetSearchAllLibrariesLibraryErrors,
): string {
  return JSON.stringify(
    GetSearchAllLibrariesLibraryErrors$outboundSchema.parse(
      getSearchAllLibrariesLibraryErrors,
    ),
  );
}

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

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

    return new GetSearchAllLibrariesUnauthorized(remapped);
  });

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

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

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

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

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

export function getSearchAllLibrariesErrorsToJSON(
  getSearchAllLibrariesErrors: GetSearchAllLibrariesErrors,
): string {
  return JSON.stringify(
    GetSearchAllLibrariesErrors$outboundSchema.parse(
      getSearchAllLibrariesErrors,
    ),
  );
}

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

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

    return new GetSearchAllLibrariesBadRequest(remapped);
  });

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

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