"use strict";
/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppendConditionFailed$ = exports.AppendConditionFailed$outboundSchema = exports.AppendConditionFailed$inboundSchema = exports.FencingToken$ = exports.FencingToken$outboundSchema = exports.FencingToken$inboundSchema = exports.SeqNum$ = exports.SeqNum$outboundSchema = exports.SeqNum$inboundSchema = exports.FencingToken = exports.SeqNum = void 0;
exports.appendConditionFailedToJSON = appendConditionFailedToJSON;
exports.appendConditionFailedFromJSON = appendConditionFailedFromJSON;
const z = __importStar(require("zod"));
const primitives_js_1 = require("../../lib/primitives.js");
const schemas_js_1 = require("../../lib/schemas.js");
const s2error_js_1 = require("./s2error.js");
/**
 * Sequence number did not match the tail of the stream.
 *
 * @remarks
 * The expected next sequence number is returned.
 */
class SeqNum extends s2error_js_1.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";
    }
}
exports.SeqNum = SeqNum;
/**
 * Fencing token did not match.
 *
 * @remarks
 * The expected fencing token is returned.
 */
class FencingToken extends s2error_js_1.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";
    }
}
exports.FencingToken = FencingToken;
/** @internal */
exports.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 = (0, primitives_js_1.remap)(v, {
        "seq_num_mismatch": "seqNumMismatch",
    });
    return new SeqNum(remapped, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
    });
});
/** @internal */
exports.SeqNum$outboundSchema = z.instanceof(SeqNum)
    .transform(v => v.data$)
    .pipe(z.object({
    seqNumMismatch: z.number().int(),
}).transform((v) => {
    return (0, primitives_js_1.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.
 */
var SeqNum$;
(function (SeqNum$) {
    /** @deprecated use `SeqNum$inboundSchema` instead. */
    SeqNum$.inboundSchema = exports.SeqNum$inboundSchema;
    /** @deprecated use `SeqNum$outboundSchema` instead. */
    SeqNum$.outboundSchema = exports.SeqNum$outboundSchema;
})(SeqNum$ || (exports.SeqNum$ = SeqNum$ = {}));
/** @internal */
exports.FencingToken$inboundSchema = z.object({
    fencing_token_mismatch: z.string(),
    request$: z.instanceof(Request),
    response$: z.instanceof(Response),
    body$: z.string(),
})
    .transform((v) => {
    const remapped = (0, primitives_js_1.remap)(v, {
        "fencing_token_mismatch": "fencingTokenMismatch",
    });
    return new FencingToken(remapped, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
    });
});
/** @internal */
exports.FencingToken$outboundSchema = z.instanceof(FencingToken)
    .transform(v => v.data$)
    .pipe(z.object({
    fencingTokenMismatch: z.string(),
}).transform((v) => {
    return (0, primitives_js_1.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.
 */
var FencingToken$;
(function (FencingToken$) {
    /** @deprecated use `FencingToken$inboundSchema` instead. */
    FencingToken$.inboundSchema = exports.FencingToken$inboundSchema;
    /** @deprecated use `FencingToken$outboundSchema` instead. */
    FencingToken$.outboundSchema = exports.FencingToken$outboundSchema;
})(FencingToken$ || (exports.FencingToken$ = FencingToken$ = {}));
/** @internal */
exports.AppendConditionFailed$inboundSchema = z.union([
    z.lazy(() => exports.FencingToken$inboundSchema),
    z.lazy(() => exports.SeqNum$inboundSchema),
]);
/** @internal */
exports.AppendConditionFailed$outboundSchema = z.union([
    z.lazy(() => exports.FencingToken$outboundSchema),
    z.lazy(() => exports.SeqNum$outboundSchema),
]);
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var AppendConditionFailed$;
(function (AppendConditionFailed$) {
    /** @deprecated use `AppendConditionFailed$inboundSchema` instead. */
    AppendConditionFailed$.inboundSchema = exports.AppendConditionFailed$inboundSchema;
    /** @deprecated use `AppendConditionFailed$outboundSchema` instead. */
    AppendConditionFailed$.outboundSchema = exports.AppendConditionFailed$outboundSchema;
})(AppendConditionFailed$ || (exports.AppendConditionFailed$ = AppendConditionFailed$ = {}));
function appendConditionFailedToJSON(appendConditionFailed) {
    return JSON.stringify(exports.AppendConditionFailed$outboundSchema.parse(appendConditionFailed));
}
function appendConditionFailedFromJSON(jsonString) {
    return (0, schemas_js_1.safeParse)(jsonString, (x) => exports.AppendConditionFailed$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AppendConditionFailed' from JSON`);
}
//# sourceMappingURL=appendconditionfailed.js.map