/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod";
import { remap as remap$ } from "../../../lib/primitives.js";

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

/**
 * Not Found or Expired
 */
export type GetTokenByPinIdResponseBodyData = {
  errors?: Array<GetTokenByPinIdPlexErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Not Found or Expired
 */
export class GetTokenByPinIdResponseBody extends Error {
  errors?: Array<GetTokenByPinIdPlexErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

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

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

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

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

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

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

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

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

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetTokenByPinIdPlexErrors$ {
  /** @deprecated use `GetTokenByPinIdPlexErrors$inboundSchema` instead. */
  export const inboundSchema = GetTokenByPinIdPlexErrors$inboundSchema;
  /** @deprecated use `GetTokenByPinIdPlexErrors$outboundSchema` instead. */
  export const outboundSchema = GetTokenByPinIdPlexErrors$outboundSchema;
  /** @deprecated use `GetTokenByPinIdPlexErrors$Outbound` instead. */
  export type Outbound = GetTokenByPinIdPlexErrors$Outbound;
}

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

    return new GetTokenByPinIdResponseBody(remapped);
  });

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

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

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

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

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

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

    return new GetTokenByPinIdBadRequest(remapped);
  });

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

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