/*
 * 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 Code = {
    BadRequest: "bad_request",
};
/**
 * A short code indicating the error code returned.
 */
export const BadRequestCode = {
    BadRequest: "bad_request",
};
export 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";
    }
}
/** @internal */
export const Code$inboundSchema = z.nativeEnum(Code);
/** @internal */
export const Code$outboundSchema = Code$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var Code$;
(function (Code$) {
    /** @deprecated use `Code$inboundSchema` instead. */
    Code$.inboundSchema = Code$inboundSchema;
    /** @deprecated use `Code$outboundSchema` instead. */
    Code$.outboundSchema = Code$outboundSchema;
})(Code$ || (Code$ = {}));
/** @internal */
export const BadRequestCode$inboundSchema = z.nativeEnum(BadRequestCode);
/** @internal */
export const BadRequestCode$outboundSchema = BadRequestCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var BadRequestCode$;
(function (BadRequestCode$) {
    /** @deprecated use `BadRequestCode$inboundSchema` instead. */
    BadRequestCode$.inboundSchema = BadRequestCode$inboundSchema;
    /** @deprecated use `BadRequestCode$outboundSchema` instead. */
    BadRequestCode$.outboundSchema = BadRequestCode$outboundSchema;
})(BadRequestCode$ || (BadRequestCode$ = {}));
/** @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(),
});
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var ErrorT$;
(function (ErrorT$) {
    /** @deprecated use `ErrorT$inboundSchema` instead. */
    ErrorT$.inboundSchema = ErrorT$inboundSchema;
    /** @deprecated use `ErrorT$outboundSchema` instead. */
    ErrorT$.outboundSchema = ErrorT$outboundSchema;
})(ErrorT$ || (ErrorT$ = {}));
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),
})
    .transform((v) => {
    return new BadRequest(v);
});
/** @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),
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var BadRequest$;
(function (BadRequest$) {
    /** @deprecated use `BadRequest$inboundSchema` instead. */
    BadRequest$.inboundSchema = BadRequest$inboundSchema;
    /** @deprecated use `BadRequest$outboundSchema` instead. */
    BadRequest$.outboundSchema = BadRequest$outboundSchema;
})(BadRequest$ || (BadRequest$ = {}));
//# sourceMappingURL=badrequest.js.map