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

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

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

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

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

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

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

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

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

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

export function getRecentlyAddedLibraryLibraryErrorsToJSON(
  getRecentlyAddedLibraryLibraryErrors: GetRecentlyAddedLibraryLibraryErrors,
): string {
  return JSON.stringify(
    GetRecentlyAddedLibraryLibraryErrors$outboundSchema.parse(
      getRecentlyAddedLibraryLibraryErrors,
    ),
  );
}

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

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

    return new GetRecentlyAddedLibraryUnauthorized(remapped);
  });

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

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

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

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

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

export function getRecentlyAddedLibraryErrorsToJSON(
  getRecentlyAddedLibraryErrors: GetRecentlyAddedLibraryErrors,
): string {
  return JSON.stringify(
    GetRecentlyAddedLibraryErrors$outboundSchema.parse(
      getRecentlyAddedLibraryErrors,
    ),
  );
}

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

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

    return new GetRecentlyAddedLibraryBadRequest(remapped);
  });

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

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