using System.Collections.Generic;
public static readonly Dictionary<string, string> AlphaCountryMap = new Dictionary<string, string>( StringComparer.OrdinalIgnoreCase )
private static readonly Dictionary<Region, string[]> RegionByCountryMap = new Dictionary<Region, string[]>
{ Region.UnitedStates, new[] {
private static readonly Dictionary<string, string> TopLevelDomainByCountryMap = new Dictionary<string, string>( StringComparer.OrdinalIgnoreCase )
private static readonly Dictionary<Region, string> SecondLevelDomainPostfixByRegion = new Dictionary<Region, string>
{ Region.UnitedStates, "us" },
private static readonly Dictionary<string, Region[]> RegionsByRegionCodeMap = new Dictionary<string, Region[]>
private static readonly Dictionary<string, string> DefaultTopLevelDomainByRegionCodeMap = new Dictionary<string, string>( StringComparer.OrdinalIgnoreCase )
public static string GetHost( string env, string countryCode, string regionCode )
if ( ( env == "qa" || env == "qa2" ) && regionCode == "ru" )
if ( ( env == "qa" || env == "qa2" ) && regionCode == "asia" )
if ( !DefaultTopLevelDomainByRegionCodeMap.TryGetValue( regionCode, out topLevelDomain ) )
string secondLevelDomain = "tlintegration";
string thirdLevelDomain = "ibe";
if ( AlphaCountryMap.ContainsKey( countryCode ) )
Region region = RegionByCountryMap.First( code => code.Value.Contains( countryCode ) ).Key;
string secondLevelDomainPostfix = SecondLevelDomainPostfixByRegion[ region ];
string thirdLevelDomainPrefix = AlphaCountryMap[ countryCode ].ToLower();
List<string> allowedRegionCodes = RegionsByRegionCodeMap
.Where( code => code.Value.Contains( region ) )
.Select( pair => pair.Key )
if ( allowedRegionCodes.Contains( regionCode ) )
if ( !TopLevelDomainByCountryMap.TryGetValue( countryCode, out topLevelDomain ) )
if ( secondLevelDomainPostfix != "" )
secondLevelDomain = $"{secondLevelDomain}-{secondLevelDomainPostfix}";
thirdLevelDomain = $"{thirdLevelDomainPrefix}-{thirdLevelDomain}";
return $"{thirdLevelDomain}.{secondLevelDomain}.{topLevelDomain}";
private static List<List<string>> TestCases = new List<List<string>>
new List<string> { "qa", "RUS", "ru", "www.qatl.ru" },
new List<string> { "qa2", "RUS", "asia", "www.qatl2.ru" },
new List<string> { "prod", "RUS", "ru", "ru-ibe.tlintegration.ru" },
new List<string> { "prod", "RUS", "asia", "ibe.tlintegration.com" },
new List<string> { "prod", "ABH", "ru", "ab-ibe.tlintegration.com" },
new List<string> { "prod", "ABH", "asia", "ibe.tlintegration.com" },
new List<string> { "prod", "USA", "ru", "ibe.tlintegration.ru" },
new List<string> { "prod", "USA", "asia", "us-ibe.tlintegration-us.com" },
new List<string> { "prod", "UKR", "ru", "ibe.tlintegration.ru" },
new List<string> { "prod", "UKR", "asia", "ua-ibe.tlintegration-eu.com" },
public static void Main()
foreach ( List<string> testCase in TestCases )
string host = RegionMapper.GetHost(testCase[0], testCase[1], testCase[2]);
if ( host != testCase[3] )
Console.WriteLine($"{testCase[0]}, {testCase[1]}, {testCase[2]}, → {host}, expected: {testCase[3]}");