/*
 * 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 Code = {
    BadRequest: "bad_request",
};
/**
 * A short code indicating the error code returned.
 */
export const BadRequestCode = {
    BadRequest: "bad_request",
};
export class BadRequest 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 = "BadRequest";
    }
}
/** @internal */
export const Code$inboundSchema = z.nativeEnum(Code);
/** @internal */
export const Code$outboundSchema = Code$inboundSchema;
/** @internal */
export const BadRequestCode$inboundSchema = z.nativeEnum(BadRequestCode);
/** @internal */
export const BadRequestCode$outboundSchema = BadRequestCode$inboundSchema;
/** @internal */
export const ErrorT$inboundSchema = z
    .object({
    code: BadRequestCode$inboundSchema,
    message: z.string(),
});
/** @internal */
export const ErrorT$outboundSchema = z.object({
    code: BadRequestCode$outboundSchema,
    message: z.string(),
});
export function errorToJSON(errorT) {
    return JSON.stringify(ErrorT$outboundSchema.parse(errorT));
}
export function errorFromJSON(jsonString) {
    return safeParse(jsonString, (x) => ErrorT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ErrorT' from JSON`);
}
/** @internal */
export const BadRequest$inboundSchema = z.object({
    title: z.string(),
    status: z.number(),
    detail: z.string(),
    instance: z.string().optional(),
    requestId: z.string().optional(),
    code: Code$inboundSchema,
    error: z.lazy(() => ErrorT$inboundSchema),
    request$: z.instanceof(Request),
    response$: z.instanceof(Response),
    body$: z.string(),
})
    .transform((v) => {
    return new BadRequest(v, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
    });
});
/** @internal */
export const 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: Code$outboundSchema,
    error: z.lazy(() => ErrorT$outboundSchema),
}));
//# sourceMappingURL=badrequest.js.map