const translitMap: Record<string, string> = {
    'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo',
    'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm',
    'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
    'ф': 'f', 'х': 'kh', 'ц': 'ts', 'ч': 'ch', 'ш': 'sh', 'щ': 'shch', 'ъ': '',
    'ы': 'y', 'ь': '', 'э': 'e', 'ю': 'yu', 'я': 'ya',
};

const transliterate = (text: string): string => {
    return text.toLowerCase().split('').map(char => translitMap[char] || char).join('');
};

const toSnakeCase = (text: string): string => {
    return text
        .toLowerCase()
        .replace(/\s+/g, '_')  // Replace spaces with underscores
        .replace(/[^a-z_0-9]/g, '') // Remove non-English letters and special chars
        .replace(/__+/g, '_') // Replace multiple underscores with single one
        .replace(/^_+|_+$/g, ''); // Trim leading/trailing underscores
};

export const convertRussianToSnakeCase = (input: string): string => {
    const transliterated = transliterate(input);
    return toSnakeCase(transliterated);
};