package lib

import (
	"github.com/ironsublimate/gomapinfer/common"
	"github.com/ironsublimate/gomapinfer/googlemaps"

	"math"
)

const ZOOM = 20

var regionMap map[string][4]float64 = map[string][4]float64{
	// cities 1 -200 pics
	// "New-York": [4]float64{40.722929, -74.019735, 40.689795, -73.984963},
	// "London":   [4]float64{51.52733184541748, -0.08075911050333019, 51.509593122993984, -0.023999584563405903},
	// "Toronto":  [4]float64{43.669194, -79.413479, 43.64102593435012, -79.37627391365903},

	// cities 2 - 328 pics
	// "Seattle":   [4]float64{47.626297, -122.353130, 47.591382, -122.316180},
	// "Tokyo":     [4]float64{35.671386, 139.722466, 35.624368, 139.755382},
	// "LA":        [4]float64{34.070393, -118.274908, 34.027270, -118.238398},
	// "Amsterdam": [4]float64{52.39296467698538, 4.864898218731434, 52.36260640016709, 4.8944481735471115},
	// "San-diego": [4]float64{32.729028, -117.177619, 32.704259, -117.145797},

	// cities 3 - 380 pics
	// "Sydney":          [4]float64{-33.869257371583146, 151.1913423178736, -33.906179449085855, 151.23072682171144},
	// "Portland":        [4]float64{45.532231, -122.695860, 45.497663, -122.653470},
	// "Columbus":        [4]float64{39.985654, -83.033001, 39.95741367491137, -82.97912312659336},
	// "Miami":           [4]float64{25.791081, -80.212756, 25.755609, -80.184534},
	// "Paris1":          [4]float64{48.83776273956148, 2.3451739560228915, 48.82708438819931, 2.3665457975690134},
	// "Paris2":          [4]float64{48.88688314910606, 2.275926399217544, 48.868181074061454, 2.3066728293618524},
	// "Rio-de-Janeiro":  [4]float64{-22.869727934866585, -43.25839351998468, -22.88001692774615, -43.238729486815586}, // 20 pics
	// "Rio-de-Janeiro1": [4]float64{-22.907568280422307, -43.239063561288, -22.92084981160786, -43.20869618879126},    // 20 pics
	// "Vancouver":  [4]float64{49.28659363692447, -123.1238499320368, 49.272592179283784, -123.09861719393453},

	// cities 4 -  364 pics
	// "Vancouver2": [4]float64{49.275716501720154, -123.03134527996049, 49.25789531870938, -122.99520171240485},
	// "Abu-Dhabi":  [4]float64{24.44082423641214, 54.43141881147327, 24.40834659304981, 54.4663771817851},
	// "CapeTown":   [4]float64{-33.91667596161162, 18.41653549743742, -33.93488677093998, 18.431699004544555},  // 20 pics
	// "CapeTown1":  [4]float64{-33.94852065980478, 18.467393241230692, -33.96213415065929, 18.478935205056246}, // left part
	// "Kyoto":      [4]float64{34.98581463940722, 135.75307223955855, 34.97178432739214, 135.7718265398684},    // 20 pics
	// "Osaka":      [4]float64{34.69106812866204, 135.4780408989561, 34.653677325565944, 135.50867161310785},   // 20 pics
	// "Madrid":     [4]float64{40.40744755363828, -3.7125490993409427, 40.39255018234745, -3.6855121776670243}, // 20 pics
	// "Milan":      [4]float64{45.464011399549754, 9.1859476473277, 45.44039031177061, 9.223400071885946},      // 20 pics
	// "Vienna":     [4]float64{48.20502968186295, 16.358026755412485, 48.197223025866016, 16.385781526280805},  // 20 pics
	// "Munich":     [4]float64{48.14407361074951, 11.583794105691581, 48.12875008225787, 11.603886303732937},   // 20 pics
	// "Incheon":    [4]float64{37.46188718929729, 126.67206848596445, 37.45074730021519, 126.69009293011173},   // 20 pics
	// cities 5
	"Dubai": [4]float64{25.23518693367323, 55.278797773694826, 25.22555925841552, 55.309997228394465}, // 20 pics
	// more cities
	// "sydney": [4]float64{-33.869257371583146, 151.1913423178736, -33.906179449085855, 151.23072682171144},
	// "Berlin": [4]float64{52.517877323534414, 13.376590057390864, 52.49943048586074, 13.431793567689029},
	// "indianapolis": [4]float64{39.791906, -86.199312, 39.745338, -86.136280},   // available at zoom 20
	// "louisville":   [4]float64{38.266052, -85.773983, 38.237431, -85.716176},   // available at zoom 20
	// "columbus": [4]float64{39.985654, -83.033001, 39.95741367491137, -82.97912312659336}, // available at zoom 20
	// "chicago":      [4]float64{41.903117, -87.679072, 41.827860, -87.602447},   // available at zoom 20
	// "milwaukee":    [4]float64{43.057586, -87.979920, 43.014847, -87.894497},   // available at zoom 20
	// "minneapolis":  [4]float64{44.999464, -93.296841, 44.960608, -93.240171},   // available at zoom 20
	// "seattle":      [4]float64{47.626297, -122.353130, 47.591382, -122.316180}, // available at zoom 20
	// "portland":     [4]float64{45.532231, -122.695860, 45.497663, -122.653470}, // available at zoom 20
	// "sf":           [4]float64{37.804770, -122.429278, 37.761525, -122.379400}, // available at zoom 20
	// "san jose":     [4]float64{37.343597, -121.905612, 37.319472, -121.884616}, // available at zoom 20
	// "la":           [4]float64{34.070393, -118.274908, 34.027270, -118.238398}, // 可以20级
	// "vegas":        [4]float64{36.177588, -115.189791, 36.080612, -115.145384}, // 可以20级
	// "phoenix":      [4]float64{33.464677, -112.088921, 33.441412, -112.061852},
	// "dallas":       [4]float64{32.798202, -96.817109, 32.772460, -96.776930},
	// "austin":       [4]float64{30.277550, -97.755393, 30.256969, -97.734987},
	// "san antonio":  [4]float64{29.440799, -98.503676, 29.418709, -98.475019},
	// "houston":      [4]float64{29.772755, -95.382410, 29.745711, -95.356047},
	// "miami":        [4]float64{25.791081, -80.212756, 25.755609, -80.184534},
	// "tampa":        [4]float64{27.959343, -82.468698, 27.940616, -82.446693},
	// "orlando":      [4]float64{28.545016, -81.393588, 28.527108, -81.375800},
	// "atlanta":      [4]float64{33.765592, -84.403740, 33.738920, -84.373764},
	// "st louis":     [4]float64{38.636738, -90.223322, 38.614568, -90.181919},
	// "nashville":    [4]float64{36.175205, -86.803698, 36.145061, -86.757950},
	// "dc":           [4]float64{38.911075, -77.046454, 38.893809, -77.025790},
	// "baltimore":    [4]float64{39.297646, -76.623223, 39.282575, -76.603782},
	// "philadelphia": [4]float64{39.961156, -75.177383, 39.946988, -75.138210},
	// "denver":       [4]float64{39.775325, -105.031729, 39.730041, -104.975639},
	// "kansas city":  [4]float64{39.114856, -94.602818, 39.080144, -94.565256},
	// "san diego":    [4]float64{32.729028, -117.177619, 32.704259, -117.145797},
	// "pittsburgh":   [4]float64{40.449522, -80.016203, 40.429688, -79.982987},
	// "montreal":     [4]float64{45.511932, -73.583147, 45.485183, -73.555746},
	// "vancouver":    [4]float64{49.292083, -123.137753, 49.267390, -123.108410},
	// "tokyo":        [4]float64{35.671386, 139.722466, 35.624368, 139.755382}, // Available at zoom 21
	// "saltlakecity": [4]float64{40.769193, -111.905448, 40.749489, -111.876258},
	// "paris":        [4]float64{48.860293, 2.317015, 48.838124, 2.346284}, // Available at zoom 20
	// "amsterdam":    [4]float64{52.376805, 4.882880, 52.363139, 4.904190},
	// "boston-seaport":           [4]float64{42.353877930051254, -71.0542310007121, 42.339801181100114, -71.02714354118453},  // Available at zoom 20
	// "singapore-hollandvillage": [4]float64{1.3248641380694455, 103.78615441691957, 1.3074744235438844, 103.80454338644206}, // Available at zoom 20
	// "singapore-onenorth": [4]float64{1.3041707251883932, 103.78381725869691, 1.2918789849494765, 103.79581908100862},
	// "singapore-queenstown":     [4]float64{1.3081961189866724, 103.77053774346285, 1.2860082865620306, 103.79154411050237},
	// "mountainview":   [4]float64{37.422004, -122.084095, 37.389712, -122.055092},                                 // Available at zoom 20
	// "nuscenes-0061": [4]float64{1.2998182029528779, 103.78731269087648, 1.2971327322347795, 103.78953052681876}, // Available at zoom 20 , {big, small, small, big}
	// "boston-seaport-test":       [4]float64{42.353882286239234, -71.05277139884521, 42.34388551797028, -71.0271449850942}, // Available at zoom 20
	// "singapore-onenorth-test":   [4]float64{1.3034951355049031, 103.78723580709516, 1.2916878710313677, 103.79577557039354},
	// "singapore-queenstown-test": [4]float64{1.308920716590731, 103.77053791060182, 1.2871315242226842, 103.78534393725282},
	// "Rio-de-Janeiro": [4]float64{-22.869727934866585, -43.25839351998468, -22.88001692774615, -43.238729486815586}, // 20 pics
	// "Rio-de-Janeiro1": [4]float64{-22.907568280422307, -43.239063561288, -22.92084981160786, -43.20869618879126}, // 20 pics
	// "Sydney": [4]float64{-33.87278626282321, 151.17370066826192, -33.886633829041706, 151.2191997023781}, // 20 pics
	// "UAE": [4]float64{24.44082423641214, 54.43141881147327, 24.40834659304981, 54.4663771817851}, // 20 pics
	// "CapeTown":  [4]float64{-33.91667596161162, 18.41653549743742, -33.93488677093998, 18.431699004544555},  // 20 pics
	// "CapeTown1": [4]float64{-33.94852065980478, 18.467393241230692, -33.96213415065929, 18.478935205056246}, // left part

	// argoverse
	// "ATX": [4]float64{30.263789, -97.73573538234076, 30.25199886595101, -97.69806142744162}, // 32 pics
	// "PIT": [4]float64{40.4745835231283, -80.00687178698455, 40.43752788077429, -79.92315563671308}, // 160 pics
	// "PAO": [4]float64{37.44362742159993, -122.17022555836475, 37.408539717221736, -122.11596739230662}, // 80 pics
	// "MIA": [4]float64{25.814630902929842, -80.21180385042612, 25.768556638684075, -80.13681431995593}, // 140 pics
	// "MIA1": [4]float64{25.814630902929842, -80.21180385042612, 25.768556638684075, -80.18299818414506}, // left part
	// "MIA2": [4]float64{25.793794261298636, -80.18299818414506, 25.7896211205545, -80.1569056554747},    // middle part
	// "MIA3": [4]float64{25.79971280004678, -80.18299818414506, 25.768556638684075, -80.13681431995593},  // right part

	// "DTW1": [4]float64{42.36170881950467, -83.08588804436806, 42.326487753008145, -83.03600981408918}, // right part 100 pics
	// "DTW3": [4]float64{42.332198955866964, -83.17959245782392, 42.32308030947477, -83.08681208716573}, // middle part 72 pics
	// "DTW2": [4]float64{42.30906902630176, -83.25869699028901, 42.3025626152425, -83.24719567830932}, // 4 pics left part
	// "WDC": [4]float64{38.93130933450816, -77.01990272043817, 38.88933343424304, -76.95527221254709}, // 120 pics

	// flyover
	// "flyover1": [4]float64{33.93291974574353, -118.2856330830274, 33.92440099670395, -118.2757451468634},
	// "flyover2": [4]float64{52.51438297330095, -1.8703803630871192, 52.50674201261203, -1.8557842868822563},
	// "flyover3": [4]float64{32.927975996203486, -96.76716234778124, 32.92199627682952, -96.75684120773975},
	// "flyover4": [4]float64{41.87788875895203, -87.65074338859056, 41.87300768405057, -87.64238562550084},
	// "flyover5": [4]float64{33.89708039809462, -84.26606844507162, 33.88696329717762, -84.25308655374916},
	// // "flyover6":  [4]float64{13.045503889909487, 77.58891120412311, 13.04092978529087, 77.59350437495681},
	// // "flyover7":  [4]float64{13.009463131891401, 80.20236388270884, 13.006269579994841, 80.20524993953957},
	// // "flyover8":  [4]float64{30.05036025783308, 31.230272549822995, 30.04786984052792, 31.234629682711077},
	// "flyover6": [4]float64{13.624463345968302, 100.734084287473, 13.619482514305329, 100.73802784232969},
	// // "flyover10": [4]float64{12.919325997225009, 77.6204939287261, 12.916081710751925, 77.6250860824486},
	// "flyover7":  [4]float64{2.9457777722517435, 101.71207640046212, 2.939188237498332, 101.71733353002466},
	// "flyover8":  [4]float64{35.689664860177466, 139.77101184795546, 35.67613983404873, 139.79264118093218},
	// "flyover9":  [4]float64{30.34697887354034, -97.71092805337236, 30.333608270925538, -97.68835458284504},
	// "flyover10": [4]float64{39.322259770756894, -76.63389755705988, 39.306255995629996, -76.61179615530786},
	// "flyover11": [4]float64{39.298883364333946, -76.8286093102321, 39.293283785095426, -76.8210525922321},
	// "flyover12": [4]float64{39.311941786095375, -76.75396550951228, 39.300585112970424, -76.73692811825877},

	//flyovernew
	// "flyovernew1":  [4]float64{39.10072765012437, -94.59863118314631, 39.09010482892732, -94.58463782285106},
	// "flyovernew2":  [4]float64{39.10227049663194, -94.57974397007018, 39.09049060183165, -94.5669358397453},
	// "flyovernew3":  [4]float64{39.10939088922283, -94.60107810952562, 39.10182544832842, -94.58823174597586},
	// "flyovernew4":  [4]float64{39.109361222413064, -94.58047040133121, 39.10129138652533, -94.56651527426081},
	// "flyovernew5":  [4]float64{39.10284574579159, -94.63167787374317, 39.09539619927485, -94.61507768845398},
	// "flyovernew6":  [4]float64{30.28004241348393, -97.77219578363085, 30.273622418506008, -97.7641122151422},
	// "flyovernew7":  [4]float64{30.238290538640733, -97.8320586526348, 30.23191913951364, -97.81940191485411},
	// "flyovernew8":  [4]float64{30.219156718310234, -97.75806061516879, 30.213637115206012, -97.74833507183088},
	// "flyovernew9":  [4]float64{35.69391641011584, 139.75437143729403, 35.690683682267704, 139.75881317544668},
	// "flyovernew10": [4]float64{35.684870313866845, 139.77632358735352, 35.68267661679173, 139.77950988911817},
	// "flyovernew11": [4]float64{35.68156520413138, 139.78525704434333, 35.68059786381716, 139.7878587871018},

	// roundabout
	// "roundabout1": [4]float64{2.9483371547251527, 101.69529708776854, 2.936427005077898, 101.7045221897491},
	// // "roundabout2":    [4]float64{10.528181607418645, 76.21117412851943, 10.520743288643091, 76.21873446262849},
	// "Paris1":      [4]float64{48.83776273956148, 2.3451739560228915, 48.82708438819931, 2.3665457975690134}, // available at zoom 20
	// "Paris2":      [4]float64{48.88688314910606, 2.275926399217544, 48.868181074061454, 2.3066728293618524}, // available at zoom 20
	// "roundabout2": [4]float64{51.570558753572165, -1.7804575077432436, 51.557547405692596, -1.759875255871945},
	// // "roundabout5":    [4]float64{10.350640472903079, 107.09070334790744, 10.347396634921372, 107.0942534418018},
	// "roundabout3": [4]float64{-33.32898658546001, 115.66168252739125, -33.34104657179713, 115.67283352131454},
	// // "roundabout7big": [4]float64{20.679894906743964, -103.42081631198525, 20.658324116699642, -103.38152687340981},
	// "roundabout4": [4]float64{51.52858009183694, -0.09286676571934308, 51.522386392522556, -0.07688328029584489},
	// "roundabout5": [4]float64{32.700992970832644, -97.36356555820969, 32.69679858835609, -97.35770883228123},

	// //suburban
	// "suburban1": [4]float64{51.477918117034555, -2.6328731499873537, 51.47242510596568, -2.6271224938283577}, // available at zoom 20
	// "suburban2": [4]float64{53.42122906442224, -2.2419982679928325, 53.40785976321503, -2.2175855378288603},  // available at zoom 20
	// "suburban3": [4]float64{40.07879127586076, -75.47868571673244, 40.06971161010952, -75.43554407390265},    // available at zoom 20
	// "suburban4": [4]float64{38.63992516090579, -90.3579044498177, 38.62212570506816, -90.30995708745199}, // available at zoom 20
	// "suburban5": [4]float64{42.34971703827646, -71.17582104808584, 42.296537795622434, -71.11522458169401},   // available at zoom 20
	// "suburban6": [4]float64{46.06566281680098, -71.9889769885027, 46.05269128838897, -71.93578422085868},     // available at zoom 20
	// "suburban7": [4]float64{43.76820734158149, -79.39005522990087, 43.761717980926754, -79.35826226727131}, // available at zoom 20
	// "suburban8": [4]float64{29.639760020151822, -95.49719933288202, 29.605520495128637, -95.47834743852589},
}

type Region struct {
	Name        string
	RadiusX     int
	RadiusY     int
	CenterGPS   common.Point
	CenterWorld common.Point
}

func GetRegions() []Region {
	var regions []Region
	for name, array := range regionMap {
		centerGPS := common.Point{
			(array[1] + array[3]) / 2,
			(array[0] + array[2]) / 2,
		}
		extreme := googlemaps.LonLatToPixel(common.Point{array[1], array[0]}, centerGPS, ZOOM)
		radiusX := int(math.Ceil(math.Abs(extreme.X) / 4096))
		radiusY := int(math.Ceil(math.Abs(extreme.Y) / 4096))
		// if name == "denver" || name == "kansas city" || name == "san diego" || name == "pittsburgh" || name == "montreal" || name == "vancouver" || name == "tokyo" || name == "saltlakecity" || name == "paris" || name == "amsterdam" {
		// 	radiusX = 1
		// 	radiusY = 1
		// }
		// only for testing zoom level is available
		// radiusX = 1
		// radiusY = 1

		regions = append(regions, Region{
			Name:        name,
			RadiusX:     radiusX,
			RadiusY:     radiusY,
			CenterGPS:   centerGPS,
			CenterWorld: googlemaps.LonLatToMeters(centerGPS), //convert latitude/longitude to Spherical Mercator EPSG:900913
		})
	}
	// regions = append(regions, Region{
	// 	Name: "boston",
	// 	RadiusX: 3,
	// 	RadiusY: 3,
	// 	CenterGPS: common.Point{-71.107810, 42.352373},
	// 	CenterWorld: googlemaps.LonLatToMeters(common.Point{-71.107810, 42.352373}),
	// })
	return regions
}
