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

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

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

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

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

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

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

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

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

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

export function getUsersUsersErrorsToJSON(
  getUsersUsersErrors: GetUsersUsersErrors,
): string {
  return JSON.stringify(
    GetUsersUsersErrors$outboundSchema.parse(getUsersUsersErrors),
  );
}

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

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

    return new GetUsersUnauthorized(remapped);
  });

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

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

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

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

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

export function getUsersErrorsToJSON(getUsersErrors: GetUsersErrors): string {
  return JSON.stringify(GetUsersErrors$outboundSchema.parse(getUsersErrors));
}

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

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

    return new GetUsersBadRequest(remapped);
  });

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

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