/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */
import * as z from "zod";
import { safeParse } from "../../lib/schemas.js";
/**
 * A short code indicating the error code returned.
 */
export const InternalServerErrorCode = {
    InternalServerError: "internal_server_error",
};
/**
 * A short code indicating the error code returned.
 */
export const InternalServerErrorErrorCode = {
    InternalServerError: "internal_server_error",
};
export class InternalServerError 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 = "InternalServerError";
    }
}
/** @internal */
export const InternalServerErrorCode$inboundSchema = z.nativeEnum(InternalServerErrorCode);
/** @internal */
export const InternalServerErrorCode$outboundSchema = InternalServerErrorCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var InternalServerErrorCode$;
(function (InternalServerErrorCode$) {
    /** @deprecated use `InternalServerErrorCode$inboundSchema` instead. */
    InternalServerErrorCode$.inboundSchema = InternalServerErrorCode$inboundSchema;
    /** @deprecated use `InternalServerErrorCode$outboundSchema` instead. */
    InternalServerErrorCode$.outboundSchema = InternalServerErrorCode$outboundSchema;
})(InternalServerErrorCode$ || (InternalServerErrorCode$ = {}));
/** @internal */
export const InternalServerErrorErrorCode$inboundSchema = z.nativeEnum(InternalServerErrorErrorCode);
/** @internal */
export const InternalServerErrorErrorCode$outboundSchema = InternalServerErrorErrorCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var InternalServerErrorErrorCode$;
(function (InternalServerErrorErrorCode$) {
    /** @deprecated use `InternalServerErrorErrorCode$inboundSchema` instead. */
    InternalServerErrorErrorCode$.inboundSchema = InternalServerErrorErrorCode$inboundSchema;
    /** @deprecated use `InternalServerErrorErrorCode$outboundSchema` instead. */
    InternalServerErrorErrorCode$.outboundSchema = InternalServerErrorErrorCode$outboundSchema;
})(InternalServerErrorErrorCode$ || (InternalServerErrorErrorCode$ = {}));
/** @internal */
export const InternalServerErrorError$inboundSchema = z.object({
    code: InternalServerErrorErrorCode$inboundSchema,
    message: z.string(),
});
/** @internal */
export const InternalServerErrorError$outboundSchema = z.object({
    code: InternalServerErrorErrorCode$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.
 */
export var InternalServerErrorError$;
(function (InternalServerErrorError$) {
    /** @deprecated use `InternalServerErrorError$inboundSchema` instead. */
    InternalServerErrorError$.inboundSchema = InternalServerErrorError$inboundSchema;
    /** @deprecated use `InternalServerErrorError$outboundSchema` instead. */
    InternalServerErrorError$.outboundSchema = InternalServerErrorError$outboundSchema;
})(InternalServerErrorError$ || (InternalServerErrorError$ = {}));
export function internalServerErrorErrorToJSON(internalServerErrorError) {
    return JSON.stringify(InternalServerErrorError$outboundSchema.parse(internalServerErrorError));
}
export function internalServerErrorErrorFromJSON(jsonString) {
    return safeParse(jsonString, (x) => InternalServerErrorError$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'InternalServerErrorError' from JSON`);
}
/** @internal */
export const InternalServerError$inboundSchema = z.object({
    title: z.string(),
    status: z.number(),
    detail: z.string(),
    instance: z.string().optional(),
    requestId: z.string().optional(),
    code: InternalServerErrorCode$inboundSchema,
    error: z.lazy(() => InternalServerErrorError$inboundSchema),
})
    .transform((v) => {
    return new InternalServerError(v);
});
/** @internal */
export const InternalServerError$outboundSchema = z.instanceof(InternalServerError)
    .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: InternalServerErrorCode$outboundSchema,
    error: z.lazy(() => InternalServerErrorError$outboundSchema),
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var InternalServerError$;
(function (InternalServerError$) {
    /** @deprecated use `InternalServerError$inboundSchema` instead. */
    InternalServerError$.inboundSchema = InternalServerError$inboundSchema;
    /** @deprecated use `InternalServerError$outboundSchema` instead. */
    InternalServerError$.outboundSchema = InternalServerError$outboundSchema;
})(InternalServerError$ || (InternalServerError$ = {}));
//# sourceMappingURL=internalservererror.js.map