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

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

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

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

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

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

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

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

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

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

export function getTransientTokenAuthenticationErrorsToJSON(
  getTransientTokenAuthenticationErrors: GetTransientTokenAuthenticationErrors,
): string {
  return JSON.stringify(
    GetTransientTokenAuthenticationErrors$outboundSchema.parse(
      getTransientTokenAuthenticationErrors,
    ),
  );
}

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

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

    return new GetTransientTokenUnauthorized(remapped);
  });

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

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

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

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

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

export function getTransientTokenErrorsToJSON(
  getTransientTokenErrors: GetTransientTokenErrors,
): string {
  return JSON.stringify(
    GetTransientTokenErrors$outboundSchema.parse(getTransientTokenErrors),
  );
}

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

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

    return new GetTransientTokenBadRequest(remapped);
  });

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

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