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