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