"use strict";
/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Unauthorized$ = exports.Unauthorized$outboundSchema = exports.Unauthorized$inboundSchema = exports.UnauthorizedError$ = exports.UnauthorizedError$outboundSchema = exports.UnauthorizedError$inboundSchema = exports.UnauthorizedErrorCode$ = exports.UnauthorizedErrorCode$outboundSchema = exports.UnauthorizedErrorCode$inboundSchema = exports.UnauthorizedCode$ = exports.UnauthorizedCode$outboundSchema = exports.UnauthorizedCode$inboundSchema = exports.Unauthorized = exports.UnauthorizedErrorCode = exports.UnauthorizedCode = void 0;
exports.unauthorizedErrorToJSON = unauthorizedErrorToJSON;
exports.unauthorizedErrorFromJSON = unauthorizedErrorFromJSON;
const z = __importStar(require("zod"));
const schemas_js_1 = require("../../lib/schemas.js");
/**
 * A short code indicating the error code returned.
 */
exports.UnauthorizedCode = {
    Unauthorized: "unauthorized",
};
/**
 * A short code indicating the error code returned.
 */
exports.UnauthorizedErrorCode = {
    Unauthorized: "unauthorized",
};
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";
    }
}
exports.Unauthorized = Unauthorized;
/** @internal */
exports.UnauthorizedCode$inboundSchema = z.nativeEnum(exports.UnauthorizedCode);
/** @internal */
exports.UnauthorizedCode$outboundSchema = exports.UnauthorizedCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var UnauthorizedCode$;
(function (UnauthorizedCode$) {
    /** @deprecated use `UnauthorizedCode$inboundSchema` instead. */
    UnauthorizedCode$.inboundSchema = exports.UnauthorizedCode$inboundSchema;
    /** @deprecated use `UnauthorizedCode$outboundSchema` instead. */
    UnauthorizedCode$.outboundSchema = exports.UnauthorizedCode$outboundSchema;
})(UnauthorizedCode$ || (exports.UnauthorizedCode$ = UnauthorizedCode$ = {}));
/** @internal */
exports.UnauthorizedErrorCode$inboundSchema = z.nativeEnum(exports.UnauthorizedErrorCode);
/** @internal */
exports.UnauthorizedErrorCode$outboundSchema = exports.UnauthorizedErrorCode$inboundSchema;
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var UnauthorizedErrorCode$;
(function (UnauthorizedErrorCode$) {
    /** @deprecated use `UnauthorizedErrorCode$inboundSchema` instead. */
    UnauthorizedErrorCode$.inboundSchema = exports.UnauthorizedErrorCode$inboundSchema;
    /** @deprecated use `UnauthorizedErrorCode$outboundSchema` instead. */
    UnauthorizedErrorCode$.outboundSchema = exports.UnauthorizedErrorCode$outboundSchema;
})(UnauthorizedErrorCode$ || (exports.UnauthorizedErrorCode$ = UnauthorizedErrorCode$ = {}));
/** @internal */
exports.UnauthorizedError$inboundSchema = z.object({
    code: exports.UnauthorizedErrorCode$inboundSchema,
    message: z.string(),
});
/** @internal */
exports.UnauthorizedError$outboundSchema = z.object({
    code: exports.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.
 */
var UnauthorizedError$;
(function (UnauthorizedError$) {
    /** @deprecated use `UnauthorizedError$inboundSchema` instead. */
    UnauthorizedError$.inboundSchema = exports.UnauthorizedError$inboundSchema;
    /** @deprecated use `UnauthorizedError$outboundSchema` instead. */
    UnauthorizedError$.outboundSchema = exports.UnauthorizedError$outboundSchema;
})(UnauthorizedError$ || (exports.UnauthorizedError$ = UnauthorizedError$ = {}));
function unauthorizedErrorToJSON(unauthorizedError) {
    return JSON.stringify(exports.UnauthorizedError$outboundSchema.parse(unauthorizedError));
}
function unauthorizedErrorFromJSON(jsonString) {
    return (0, schemas_js_1.safeParse)(jsonString, (x) => exports.UnauthorizedError$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UnauthorizedError' from JSON`);
}
/** @internal */
exports.Unauthorized$inboundSchema = z.object({
    title: z.string(),
    status: z.number(),
    detail: z.string(),
    instance: z.string().optional(),
    requestId: z.string().optional(),
    code: exports.UnauthorizedCode$inboundSchema,
    error: z.lazy(() => exports.UnauthorizedError$inboundSchema),
})
    .transform((v) => {
    return new Unauthorized(v);
});
/** @internal */
exports.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: exports.UnauthorizedCode$outboundSchema,
    error: z.lazy(() => exports.UnauthorizedError$outboundSchema),
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
var Unauthorized$;
(function (Unauthorized$) {
    /** @deprecated use `Unauthorized$inboundSchema` instead. */
    Unauthorized$.inboundSchema = exports.Unauthorized$inboundSchema;
    /** @deprecated use `Unauthorized$outboundSchema` instead. */
    Unauthorized$.outboundSchema = exports.Unauthorized$outboundSchema;
})(Unauthorized$ || (exports.Unauthorized$ = Unauthorized$ = {}));
//# sourceMappingURL=unauthorized.js.map