/*
 * 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 { S2Error } from "./s2error.js";
/**
 * Sequence number did not match the tail of the stream.
 *
 * @remarks
 * The expected next sequence number is returned.
 */
export class SeqNum extends S2Error {
    constructor(err, httpMeta) {
        const message = "message" in err && typeof err.message === "string"
            ? err.message
            : `API error occurred: ${JSON.stringify(err)}`;
        super(message, httpMeta);
        this.data$ = err;
        this.seqNumMismatch = err.seqNumMismatch;
        this.name = "SeqNum";
    }
}
/**
 * Fencing token did not match.
 *
 * @remarks
 * The expected fencing token is returned.
 */
export class FencingToken extends S2Error {
    constructor(err, httpMeta) {
        const message = "message" in err && typeof err.message === "string"
            ? err.message
            : `API error occurred: ${JSON.stringify(err)}`;
        super(message, httpMeta);
        this.data$ = err;
        this.fencingTokenMismatch = err.fencingTokenMismatch;
        this.name = "FencingToken";
    }
}
/** @internal */
export const SeqNum$inboundSchema = z
    .object({
    seq_num_mismatch: z.number().int(),
    request$: z.instanceof(Request),
    response$: z.instanceof(Response),
    body$: z.string(),
})
    .transform((v) => {
    const remapped = remap$(v, {
        "seq_num_mismatch": "seqNumMismatch",
    });
    return new SeqNum(remapped, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
    });
});
/** @internal */
export const SeqNum$outboundSchema = z.instanceof(SeqNum)
    .transform(v => v.data$)
    .pipe(z.object({
    seqNumMismatch: z.number().int(),
}).transform((v) => {
    return remap$(v, {
        seqNumMismatch: "seq_num_mismatch",
    });
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var SeqNum$;
(function (SeqNum$) {
    /** @deprecated use `SeqNum$inboundSchema` instead. */
    SeqNum$.inboundSchema = SeqNum$inboundSchema;
    /** @deprecated use `SeqNum$outboundSchema` instead. */
    SeqNum$.outboundSchema = SeqNum$outboundSchema;
})(SeqNum$ || (SeqNum$ = {}));
/** @internal */
export const FencingToken$inboundSchema = z.object({
    fencing_token_mismatch: z.string(),
    request$: z.instanceof(Request),
    response$: z.instanceof(Response),
    body$: z.string(),
})
    .transform((v) => {
    const remapped = remap$(v, {
        "fencing_token_mismatch": "fencingTokenMismatch",
    });
    return new FencingToken(remapped, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
    });
});
/** @internal */
export const FencingToken$outboundSchema = z.instanceof(FencingToken)
    .transform(v => v.data$)
    .pipe(z.object({
    fencingTokenMismatch: z.string(),
}).transform((v) => {
    return remap$(v, {
        fencingTokenMismatch: "fencing_token_mismatch",
    });
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var FencingToken$;
(function (FencingToken$) {
    /** @deprecated use `FencingToken$inboundSchema` instead. */
    FencingToken$.inboundSchema = FencingToken$inboundSchema;
    /** @deprecated use `FencingToken$outboundSchema` instead. */
    FencingToken$.outboundSchema = FencingToken$outboundSchema;
})(FencingToken$ || (FencingToken$ = {}));
/** @internal */
export const AppendConditionFailed$inboundSchema = z.union([
    z.lazy(() => FencingToken$inboundSchema),
    z.lazy(() => SeqNum$inboundSchema),
]);
/** @internal */
export const AppendConditionFailed$outboundSchema = z.union([
    z.lazy(() => FencingToken$outboundSchema),
    z.lazy(() => SeqNum$outboundSchema),
]);
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var AppendConditionFailed$;
(function (AppendConditionFailed$) {
    /** @deprecated use `AppendConditionFailed$inboundSchema` instead. */
    AppendConditionFailed$.inboundSchema = AppendConditionFailed$inboundSchema;
    /** @deprecated use `AppendConditionFailed$outboundSchema` instead. */
    AppendConditionFailed$.outboundSchema = AppendConditionFailed$outboundSchema;
})(AppendConditionFailed$ || (AppendConditionFailed$ = {}));
export function appendConditionFailedToJSON(appendConditionFailed) {
    return JSON.stringify(AppendConditionFailed$outboundSchema.parse(appendConditionFailed));
}
export function appendConditionFailedFromJSON(jsonString) {
    return safeParse(jsonString, (x) => AppendConditionFailed$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AppendConditionFailed' from JSON`);
}
//# sourceMappingURL=appendconditionfailed.js.map