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

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

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

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

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

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

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

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

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

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

export function getAvailableClientsServerErrorsToJSON(
  getAvailableClientsServerErrors: GetAvailableClientsServerErrors,
): string {
  return JSON.stringify(
    GetAvailableClientsServerErrors$outboundSchema.parse(
      getAvailableClientsServerErrors,
    ),
  );
}

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

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

    return new GetAvailableClientsUnauthorized(remapped);
  });

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

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

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

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

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

export function getAvailableClientsErrorsToJSON(
  getAvailableClientsErrors: GetAvailableClientsErrors,
): string {
  return JSON.stringify(
    GetAvailableClientsErrors$outboundSchema.parse(getAvailableClientsErrors),
  );
}

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

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

    return new GetAvailableClientsBadRequest(remapped);
  });

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

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