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

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

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

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

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

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

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

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

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

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

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

    return new GetLibraryDetailsUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new GetLibraryDetailsBadRequest(remapped);
  });

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

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