/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */
import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { InkeepAnalyticsError } from "./inkeepanalyticserror.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 InkeepAnalyticsError {
    constructor(err, httpMeta) {
        const message = err.error?.message
            || `API error occurred: ${JSON.stringify(err)}`;
        super(message, httpMeta);
        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 */
export const UnprocessableEntityErrorCode$inboundSchema = z.nativeEnum(UnprocessableEntityErrorCode);
/** @internal */
export const UnprocessableEntityErrorCode$outboundSchema = UnprocessableEntityErrorCode$inboundSchema;
/** @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(),
});
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),
    request$: z.instanceof(Request),
    response$: z.instanceof(Response),
    body$: z.string(),
})
    .transform((v) => {
    return new UnprocessableEntity(v, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
    });
});
/** @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),
}));
//# sourceMappingURL=unprocessableentity.js.map