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

import * as z from "zod/v3";
import { LaunchDarklyError } from "./launchdarklyerror.js";

export type PatchFailedErrorRepData = {
  /**
   * Specific error code encountered
   */
  code: string;
  /**
   * Description of the error
   */
  message: string;
};

export class PatchFailedErrorRep extends LaunchDarklyError {
  /**
   * Specific error code encountered
   */
  code: string;

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

  constructor(
    err: PatchFailedErrorRepData,
    httpMeta: { response: Response; request: Request; body: string },
  ) {
    const message = err.message || `API error occurred: ${JSON.stringify(err)}`;
    super(message, httpMeta);
    this.data$ = err;
    this.code = err.code;

    this.name = "PatchFailedErrorRep";
  }
}

/** @internal */
export const PatchFailedErrorRep$inboundSchema: z.ZodType<
  PatchFailedErrorRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.string(),
  message: z.string(),
  request$: z.instanceof(Request),
  response$: z.instanceof(Response),
  body$: z.string(),
})
  .transform((v) => {
    return new PatchFailedErrorRep(v, {
      request: v.request$,
      response: v.response$,
      body: v.body$,
    });
  });

/** @internal */
export type PatchFailedErrorRep$Outbound = {
  code: string;
  message: string;
};

/** @internal */
export const PatchFailedErrorRep$outboundSchema: z.ZodType<
  PatchFailedErrorRep$Outbound,
  z.ZodTypeDef,
  PatchFailedErrorRep
> = z.instanceof(PatchFailedErrorRep)
  .transform(v => v.data$)
  .pipe(z.object({
    code: z.string(),
    message: z.string(),
  }));
