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

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

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

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

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

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

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

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

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

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

export function getUserFriendsPlexErrorsToJSON(
  getUserFriendsPlexErrors: GetUserFriendsPlexErrors,
): string {
  return JSON.stringify(
    GetUserFriendsPlexErrors$outboundSchema.parse(getUserFriendsPlexErrors),
  );
}

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

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

    return new GetUserFriendsUnauthorized(remapped);
  });

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

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

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

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

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

export function getUserFriendsErrorsToJSON(
  getUserFriendsErrors: GetUserFriendsErrors,
): string {
  return JSON.stringify(
    GetUserFriendsErrors$outboundSchema.parse(getUserFriendsErrors),
  );
}

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

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

    return new GetUserFriendsBadRequest(remapped);
  });

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

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