/*
 * 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 GetPinErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

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

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

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

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

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

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

export function getPinErrorsToJSON(getPinErrors: GetPinErrors): string {
  return JSON.stringify(GetPinErrors$outboundSchema.parse(getPinErrors));
}

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

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

    return new GetPinBadRequest(remapped);
  });

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

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