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

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

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

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

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

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

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

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

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

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

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

    return new GetRefreshLibraryMetadataUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new GetRefreshLibraryMetadataBadRequest(remapped);
  });

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

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