/*
 * 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 UnprocessableEntityCode = {
    UnprocessableEntity: "unprocessable_entity",
};
/**
 * A short code indicating the error code returned.
 */
export const UnprocessableEntityErrorCode = {
    UnprocessableEntity: "unprocessable_entity",
};
export class UnprocessableEntity 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 = "UnprocessableEntity";
    }
}
/** @internal */
export const UnprocessableEntityCode$inboundSchema = z.nativeEnum(UnprocessableEntityCode);
/** @internal */
export const UnprocessableEntityCode$outboundSchema = UnprocessableEntityCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var UnprocessableEntityCode$;
(function (UnprocessableEntityCode$) {
    /** @deprecated use `UnprocessableEntityCode$inboundSchema` instead. */
    UnprocessableEntityCode$.inboundSchema = UnprocessableEntityCode$inboundSchema;
    /** @deprecated use `UnprocessableEntityCode$outboundSchema` instead. */
    UnprocessableEntityCode$.outboundSchema = UnprocessableEntityCode$outboundSchema;
})(UnprocessableEntityCode$ || (UnprocessableEntityCode$ = {}));
/** @internal */
export const UnprocessableEntityErrorCode$inboundSchema = z.nativeEnum(UnprocessableEntityErrorCode);
/** @internal */
export const UnprocessableEntityErrorCode$outboundSchema = UnprocessableEntityErrorCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var UnprocessableEntityErrorCode$;
(function (UnprocessableEntityErrorCode$) {
    /** @deprecated use `UnprocessableEntityErrorCode$inboundSchema` instead. */
    UnprocessableEntityErrorCode$.inboundSchema = UnprocessableEntityErrorCode$inboundSchema;
    /** @deprecated use `UnprocessableEntityErrorCode$outboundSchema` instead. */
    UnprocessableEntityErrorCode$.outboundSchema = UnprocessableEntityErrorCode$outboundSchema;
})(UnprocessableEntityErrorCode$ || (UnprocessableEntityErrorCode$ = {}));
/** @internal */
export const UnprocessableEntityError$inboundSchema = z.object({
    code: UnprocessableEntityErrorCode$inboundSchema,
    message: z.string(),
});
/** @internal */
export const UnprocessableEntityError$outboundSchema = z.object({
    code: UnprocessableEntityErrorCode$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 UnprocessableEntityError$;
(function (UnprocessableEntityError$) {
    /** @deprecated use `UnprocessableEntityError$inboundSchema` instead. */
    UnprocessableEntityError$.inboundSchema = UnprocessableEntityError$inboundSchema;
    /** @deprecated use `UnprocessableEntityError$outboundSchema` instead. */
    UnprocessableEntityError$.outboundSchema = UnprocessableEntityError$outboundSchema;
})(UnprocessableEntityError$ || (UnprocessableEntityError$ = {}));
export function unprocessableEntityErrorToJSON(unprocessableEntityError) {
    return JSON.stringify(UnprocessableEntityError$outboundSchema.parse(unprocessableEntityError));
}
export function unprocessableEntityErrorFromJSON(jsonString) {
    return safeParse(jsonString, (x) => UnprocessableEntityError$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UnprocessableEntityError' from JSON`);
}
/** @internal */
export const UnprocessableEntity$inboundSchema = z.object({
    title: z.string(),
    status: z.number(),
    detail: z.string(),
    instance: z.string().optional(),
    requestId: z.string().optional(),
    code: UnprocessableEntityCode$inboundSchema,
    error: z.lazy(() => UnprocessableEntityError$inboundSchema),
})
    .transform((v) => {
    return new UnprocessableEntity(v);
});
/** @internal */
export const UnprocessableEntity$outboundSchema = z.instanceof(UnprocessableEntity)
    .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: UnprocessableEntityCode$outboundSchema,
    error: z.lazy(() => UnprocessableEntityError$outboundSchema),
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var UnprocessableEntity$;
(function (UnprocessableEntity$) {
    /** @deprecated use `UnprocessableEntity$inboundSchema` instead. */
    UnprocessableEntity$.inboundSchema = UnprocessableEntity$inboundSchema;
    /** @deprecated use `UnprocessableEntity$outboundSchema` instead. */
    UnprocessableEntity$.outboundSchema = UnprocessableEntity$outboundSchema;
})(UnprocessableEntity$ || (UnprocessableEntity$ = {}));
//# sourceMappingURL=unprocessableentity.js.map