"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationErrorSchema = exports.TimeoutErrorSchema = exports.NetworkErrorSchema = exports.ServerErrorSchema = exports.RateLimitErrorSchema = exports.ConflictErrorSchema = exports.NotFoundErrorSchema = exports.AuthorizationErrorSchema = exports.AuthenticationErrorSchema = exports.ValidationErrorSchema = exports.ErrorSchema = exports.ErrorCategorySchema = exports.ErrorSeveritySchema = void 0;
const zod_1 = require("zod");
exports.ErrorSeveritySchema = zod_1.z.enum(['critical', 'error', 'warning', 'info']);
exports.ErrorCategorySchema = zod_1.z.enum([
    'validation',
    'authentication',
    'authorization',
    'notFound',
    'conflict',
    'rateLimit',
    'server',
    'network',
    'timeout',
    'unknown'
]);
exports.ErrorSchema = zod_1.z.object({
    code: zod_1.z.string(),
    message: zod_1.z.string(),
    category: exports.ErrorCategorySchema,
    severity: exports.ErrorSeveritySchema,
    timestamp: zod_1.z.string(),
    details: zod_1.z.unknown().optional(),
    metadata: zod_1.z.record(zod_1.z.unknown()).optional()
});
exports.ValidationErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('validation'),
    field: zod_1.z.string().optional(),
    path: zod_1.z.array(zod_1.z.string()).optional(),
    constraints: zod_1.z.record(zod_1.z.string()).optional()
});
exports.AuthenticationErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('authentication'),
    reason: zod_1.z.string().optional(),
    redirectUrl: zod_1.z.string().optional()
});
exports.AuthorizationErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('authorization'),
    requiredPermissions: zod_1.z.array(zod_1.z.string()).optional(),
    resource: zod_1.z.string().optional(),
    action: zod_1.z.string().optional()
});
exports.NotFoundErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('notFound'),
    resource: zod_1.z.string().optional(),
    identifier: zod_1.z.string().optional()
});
exports.ConflictErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('conflict'),
    resource: zod_1.z.string().optional(),
    identifier: zod_1.z.string().optional(),
    existingValue: zod_1.z.unknown().optional(),
    conflictingValue: zod_1.z.unknown().optional()
});
exports.RateLimitErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('rateLimit'),
    limit: zod_1.z.number().optional(),
    reset: zod_1.z.string().optional(),
    retryAfter: zod_1.z.number().optional()
});
exports.ServerErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('server'),
    stack: zod_1.z.string().optional(),
    component: zod_1.z.string().optional()
});
exports.NetworkErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('network'),
    url: zod_1.z.string().optional(),
    method: zod_1.z.string().optional(),
    status: zod_1.z.number().optional(),
    statusText: zod_1.z.string().optional()
});
exports.TimeoutErrorSchema = exports.ErrorSchema.extend({
    category: zod_1.z.literal('timeout'),
    timeout: zod_1.z.number().optional(),
    operation: zod_1.z.string().optional()
});
exports.ApplicationErrorSchema = zod_1.z.discriminatedUnion('category', [
    exports.ValidationErrorSchema,
    exports.AuthenticationErrorSchema,
    exports.AuthorizationErrorSchema,
    exports.NotFoundErrorSchema,
    exports.ConflictErrorSchema,
    exports.RateLimitErrorSchema,
    exports.ServerErrorSchema,
    exports.NetworkErrorSchema,
    exports.TimeoutErrorSchema,
    exports.ErrorSchema
]);
//# sourceMappingURL=errors.js.map