"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.classifyPattern = classifyPattern;
exports.inferSource = inferSource;
const SUBCATEGORY_MAP = {
    variable_declaration: ['let_to_const', 'var_to_let', 'type_inference', 'explicit_type'],
    type_annotation: ['add_type', 'remove_type', 'change_type', 'union_type'],
    modifier_change: ['public_private', 'readonly', 'static', 'async_export'],
    import_change: ['named_import', 'default_import', 'namespace_import', 'dynamic_import'],
    error_handling: ['try_catch', 'result_type', 'optional_chaining', 'null_check'],
    function_style: ['arrow_function', 'async_function', 'generator', 'method_shorthand'],
    string_style: ['template_literal', 'single_quotes', 'double_quotes', 'concatenation'],
    null_safety: ['optional_chaining', 'null_coalescing', 'truthy_check', 'explicit_null'],
    destructuring: ['object_destructure', 'array_destructure', 'rename_destructure', 'default_value'],
    async_await: ['promise_to_await', 'async_function', 'promise_all', 'error_handling'],
    structural: ['extract_function', 'inline_function', 'reorder', 'rename'],
    testing: ['add_test', 'remove_test', 'update_test', 'mock_injection'],
    naming: ['camel_case', 'snake_case', 'pascal_case', 'rename_variable'],
    loop_style: ['for_to_forEach', 'forEach_to_map', 'for_to_reduce', 'while_to_for'],
    debug_style: ['remove_console', 'add_logging', 'conditional_debug', 'comment_out'],
    api_pattern: ['fetch_to_axios', 'callback_to_promise', 'error_handling', 'retry_logic'],
    state_management: ['local_to_global', 'redux_pattern', 'context_api', 'recoil'],
    security: ['sanitize_input', 'parameterize_query', 'escape_output', 'validate_input'],
    performance: ['memoize', 'lazy_load', 'batch_updates', 'throttle_debounce'],
    logging: ['error_logging', 'info_logging', 'structured_logging', 'debug_logging'],
};
function classifyPattern(category, from, to, language, source) {
    const subcategories = SUBCATEGORY_MAP[category] || ['general'];
    const subcategory = inferSubcategory(subcategories, from, to);
    const complexity = inferComplexity(category, from, to);
    const risk = inferRisk(category, from, to);
    return {
        language: language || 'unknown',
        subcategory,
        complexity,
        risk,
        source,
    };
}
function inferSubcategory(subcategories, from, to) {
    for (const sub of subcategories) {
        const keywords = sub.split('_');
        const matchCount = keywords.filter((k) => from.toLowerCase().includes(k) || to.toLowerCase().includes(k)).length;
        if (matchCount >= 2)
            return sub;
    }
    if (from.includes('=>') || to.includes('=>'))
        return 'arrow_function';
    if (from.includes('try') || to.includes('try') || from.includes('catch') || to.includes('catch'))
        return 'try_catch';
    if (from.includes('await') || to.includes('await'))
        return 'promise_to_await';
    return subcategories[0];
}
function inferComplexity(category, from, to) {
    const fromLen = from.length;
    const toLen = to.length;
    const changedLines = Math.abs(from.split('\n').length - to.split('\n').length);
    if (changedLines > 5 || fromLen > 200 || toLen > 200)
        return 'high';
    if (changedLines > 2 || fromLen > 80 || toLen > 80)
        return 'medium';
    return 'low';
}
function inferRisk(category, from, to) {
    const highRiskCategories = ['security', 'performance', 'error_handling', 'state_management'];
    if (highRiskCategories.includes(category))
        return 'high';
    if (category === 'testing' || category === 'naming' || category === 'string_style')
        return 'low';
    return 'medium';
}
function inferSource(stepUsed) {
    switch (stepUsed) {
        case 'ast': return 'ast';
        case 'regex': return 'regex';
        case 'heuristic': return 'heuristic';
        case 'combined': return 'ast';
        default: return 'manual';
    }
}
//# sourceMappingURL=pattern-classifier.js.map