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

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

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

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

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

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

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

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

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

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

export function getLibraryItemsLibraryErrorsToJSON(
  getLibraryItemsLibraryErrors: GetLibraryItemsLibraryErrors,
): string {
  return JSON.stringify(
    GetLibraryItemsLibraryErrors$outboundSchema.parse(
      getLibraryItemsLibraryErrors,
    ),
  );
}

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

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

    return new GetLibraryItemsUnauthorized(remapped);
  });

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

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

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

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

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

export function getLibraryItemsErrorsToJSON(
  getLibraryItemsErrors: GetLibraryItemsErrors,
): string {
  return JSON.stringify(
    GetLibraryItemsErrors$outboundSchema.parse(getLibraryItemsErrors),
  );
}

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

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

    return new GetLibraryItemsBadRequest(remapped);
  });

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

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