"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.BadRequest$ = exports.BadRequest$outboundSchema = exports.BadRequest$inboundSchema = exports.ErrorT$ = exports.ErrorT$outboundSchema = exports.ErrorT$inboundSchema = exports.BadRequestCode$ = exports.BadRequestCode$outboundSchema = exports.BadRequestCode$inboundSchema = exports.Code$ = exports.Code$outboundSchema = exports.Code$inboundSchema = exports.BadRequest = exports.BadRequestCode = exports.Code = void 0;
exports.errorToJSON = errorToJSON;
exports.errorFromJSON = errorFromJSON;
const z = __importStar(require("zod"));
const schemas_js_1 = require("../../lib/schemas.js");
/**
 * A short code indicating the error code returned.
 */
exports.Code = {
    BadRequest: "bad_request",
};
/**
 * A short code indicating the error code returned.
 */
exports.BadRequestCode = {
    BadRequest: "bad_request",
};
class BadRequest extends Error {
    constructor(err) {
        const message = "message" in err && typeof err.message === "string"
            ? err.message
            : `API error occurred: ${JSON.stringify(err)}`;
        super(message);
        this.data$ = err;
        this.title = err.title;
        this.status = err.status;
        this.detail = err.detail;
        if (err.instance != null)
            this.instance = err.instance;
        if (err.requestId != null)
            this.requestId = err.requestId;
        this.code = err.code;
        this.error = err.error;
        this.name = "BadRequest";
    }
}
exports.BadRequest = BadRequest;
/** @internal */
exports.Code$inboundSchema = z.nativeEnum(exports.Code);
/** @internal */
exports.Code$outboundSchema = exports.Code$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var Code$;
(function (Code$) {
    /** @deprecated use `Code$inboundSchema` instead. */
    Code$.inboundSchema = exports.Code$inboundSchema;
    /** @deprecated use `Code$outboundSchema` instead. */
    Code$.outboundSchema = exports.Code$outboundSchema;
})(Code$ || (exports.Code$ = Code$ = {}));
/** @internal */
exports.BadRequestCode$inboundSchema = z.nativeEnum(exports.BadRequestCode);
/** @internal */
exports.BadRequestCode$outboundSchema = exports.BadRequestCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var BadRequestCode$;
(function (BadRequestCode$) {
    /** @deprecated use `BadRequestCode$inboundSchema` instead. */
    BadRequestCode$.inboundSchema = exports.BadRequestCode$inboundSchema;
    /** @deprecated use `BadRequestCode$outboundSchema` instead. */
    BadRequestCode$.outboundSchema = exports.BadRequestCode$outboundSchema;
})(BadRequestCode$ || (exports.BadRequestCode$ = BadRequestCode$ = {}));
/** @internal */
exports.ErrorT$inboundSchema = z
    .object({
    code: exports.BadRequestCode$inboundSchema,
    message: z.string(),
});
/** @internal */
exports.ErrorT$outboundSchema = z.object({
    code: exports.BadRequestCode$outboundSchema,
    message: z.string(),
});
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var ErrorT$;
(function (ErrorT$) {
    /** @deprecated use `ErrorT$inboundSchema` instead. */
    ErrorT$.inboundSchema = exports.ErrorT$inboundSchema;
    /** @deprecated use `ErrorT$outboundSchema` instead. */
    ErrorT$.outboundSchema = exports.ErrorT$outboundSchema;
})(ErrorT$ || (exports.ErrorT$ = ErrorT$ = {}));
function errorToJSON(errorT) {
    return JSON.stringify(exports.ErrorT$outboundSchema.parse(errorT));
}
function errorFromJSON(jsonString) {
    return (0, schemas_js_1.safeParse)(jsonString, (x) => exports.ErrorT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ErrorT' from JSON`);
}
/** @internal */
exports.BadRequest$inboundSchema = z.object({
    title: z.string(),
    status: z.number(),
    detail: z.string(),
    instance: z.string().optional(),
    requestId: z.string().optional(),
    code: exports.Code$inboundSchema,
    error: z.lazy(() => exports.ErrorT$inboundSchema),
})
    .transform((v) => {
    return new BadRequest(v);
});
/** @internal */
exports.BadRequest$outboundSchema = z.instanceof(BadRequest)
    .transform(v => v.data$)
    .pipe(z.object({
    title: z.string(),
    status: z.number(),
    detail: z.string(),
    instance: z.string().optional(),
    requestId: z.string().optional(),
    code: exports.Code$outboundSchema,
    error: z.lazy(() => exports.ErrorT$outboundSchema),
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var BadRequest$;
(function (BadRequest$) {
    /** @deprecated use `BadRequest$inboundSchema` instead. */
    BadRequest$.inboundSchema = exports.BadRequest$inboundSchema;
    /** @deprecated use `BadRequest$outboundSchema` instead. */
    BadRequest$.outboundSchema = exports.BadRequest$outboundSchema;
})(BadRequest$ || (exports.BadRequest$ = BadRequest$ = {}));
//# sourceMappingURL=badrequest.js.map