/**
 * 路由配置验证器
 * 使用 Zod 进行配置验证，并提供友好的错误信息
 */ import { ConfigValidationError } from "../../config/ConfigValidator";
import { logger } from "../../../utils";
import { safeValidateRouterConfig } from "./schema";
/**
 * 路由配置验证器
 */ export class RouterConfigValidator {
    /**
   * 验证路由配置
   * 
   * @param config - 要验证的路由配置
   * @returns 验证后的路由配置
   * @throws ConfigValidationError 如果配置验证失败
   */ static validate(config) {
        const result = safeValidateRouterConfig(config);
        if (!result.success) {
            // 构建友好的错误信息
            const errorMessages = result.error.issues.map((issue)=>{
                const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
                return `路由配置项 "${path}": ${issue.message}`;
            });
            const friendlyMessage = `路由配置验证失败:\n${errorMessages.join('\n')}`;
            logger.error('路由配置验证失败', {
                errors: result.error.issues,
                config
            });
            throw new ConfigValidationError(friendlyMessage, result.error);
        }
        return result.data;
    }
    /**
   * 安全验证路由配置（不抛出异常）
   * 
   * @param config - 要验证的路由配置
   * @returns 验证结果
   */ static safeValidate(config) {
        return safeValidateRouterConfig(config);
    }
    /**
   * 验证路由配置并提供修复建议
   * 
   * @param config - 要验证的路由配置
   * @returns 验证结果和修复建议
   */ static validateWithSuggestions(config) {
        const result = safeValidateRouterConfig(config);
        if (!result.success) {
            const suggestions = [];
            result.error.issues.forEach((issue)=>{
                const path = issue.path.join('.');
                // 根据错误类型提供修复建议
                if (issue.code === 'invalid_type') {
                    const invalidTypeIssue = issue;
                    suggestions.push(`配置项 "${path}" 类型错误: 期望 ${invalidTypeIssue.expected}，实际 ${invalidTypeIssue.received}`);
                } else if (issue.code === 'too_small') {
                    suggestions.push(`配置项 "${path}" 值太小: ${issue.message}`);
                } else if (issue.code === 'too_big') {
                    suggestions.push(`配置项 "${path}" 值太大: ${issue.message}`);
                } else {
                    suggestions.push(`配置项 "${path}": ${issue.message}`);
                }
            });
            return {
                success: false,
                errors: result.error.issues,
                suggestions
            };
        }
        return {
            success: true,
            data: result.data
        };
    }
}

//# sourceMappingURL=RouterConfigValidator.js.map