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

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

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

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

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

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

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

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

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

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

export function getTokenDetailsAuthenticationErrorsToJSON(
  getTokenDetailsAuthenticationErrors: GetTokenDetailsAuthenticationErrors,
): string {
  return JSON.stringify(
    GetTokenDetailsAuthenticationErrors$outboundSchema.parse(
      getTokenDetailsAuthenticationErrors,
    ),
  );
}

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

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

    return new GetTokenDetailsUnauthorized(remapped);
  });

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

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

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

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

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

export function getTokenDetailsErrorsToJSON(
  getTokenDetailsErrors: GetTokenDetailsErrors,
): string {
  return JSON.stringify(
    GetTokenDetailsErrors$outboundSchema.parse(getTokenDetailsErrors),
  );
}

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

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

    return new GetTokenDetailsBadRequest(remapped);
  });

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

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