package cost

import (
	"encoding/csv"
	"strings"

	"github.com/apex/log"
)

// tlds is a map of tlds to price.
var tlds = map[string]string{}

// Domain returns the price of domain's tld.
func Domain(domain string) string {
	return TLD(strings.SplitN(domain, ".", 2)[1])
}

// TLD returns the price of a tld.
func TLD(tld string) string {
	return tlds[tld]
}

// priceList is a raw CSV price list.
var priceList = `
ac,$48.00
academy,$32.00
accountants,$94.00
adult,$88.00
agency,$19.00
apartments,$47.00
associates,$29.00
auction,$29.00
audio,$13.00
band,$22.00
bargains,$30.00
be,$9.00
berlin,$52.00
bike,$32.00
bingo,$47.00
biz,$12.00
black,$43.00
blue,$15.00
boutique,$30.00
builders,$32.00
business,$18.00
buzz,$37.00
ca,$13.00
cab,$32.00
cafe,$31.00
camera,$46.00
camp,$46.00
capital,$47.00
cards,$29.00
care,$29.00
careers,$35.00
cash,$29.00
casino,$141.00
catering,$29.00
cc,$12.00
center,$21.00
ceo,$74.00
ch,$12.00
chat,$29.00
cheap,$30.00
church,$29.00
city,$19.00
cl,$93.00*
cloud,$23.00
claims,$47.00
cleaning,$46.00
click,$7.00
clinic,$47.00
clothing,$32.00
club,$12.00
co,$25.00
co.nz,$24.00
co.uk,$9.00
co.za,$13.00
coach,$47.00
codes,$35.00
coffee,$32.00
college,$69.00
com,$12.00
com.ar,$76.00*
com.au,$15.00
com.br,$58.00*
com.mx,$34.00
com.sg,$47.00*
community,$29.00
company,$18.00
computer,$32.00
condos,$49.00
construction,$32.00
consulting,$29.00
contractors,$32.00
cool,$30.00
coupons,$51.00
credit,$94.00
creditcard,$141.00
cruises,$49.00
dance,$22.00
dating,$49.00
de,$9.00
deals,$29.00
delivery,$47.00
democrat,$30.00
dental,$47.00
diamonds,$35.00
diet,$19.00
digital,$29.00
direct,$29.00
directory,$21.00
discount,$29.00
dog,$46.00
domains,$32.00
education,$21.00
email,$25.00
energy,$94.00
engineering,$47.00
enterprises,$32.00
equipment,$21.00
es,$10.00
estate,$32.00
eu,$13.00
events,$30.00
exchange,$29.00
expert,$49.00
exposed,$19.00
express,$31.00
fail,$29.00
farm,$32.00
fi,$24.00
finance,$47.00
financial,$47.00
fish,$29.00
fitness,$29.00
flights,$49.00
florist,$32.00
flowers,$25.00
fm,$92.00
football,$19.00
forsale,$29.00
foundation,$30.00
fr,$12.00
fund,$47.00
furniture,$47.00
futbol,$12.00
fyi,$20.00
gallery,$21.00
gg,$75.00
gift,$20.00
gifts,$19.00
glass,$46.00
global,$71.00
gold,$101.00
golf,$51.00
graphics,$21.00
gratis,$19.00
green,$71.00
gripe,$29.00
guide,$29.00
guitars,$30.00
guru,$25.00
haus,$29.00
healthcare,$47.00
help,$19.00
hiv,$254.00
hockey,$51.00
holdings,$35.00
holiday,$35.00
host,$93.00
hosting,$29.00
house,$32.00
im,$19.00
immo,$29.00
immobilien,$30.00
in,$15.00
industries,$29.00
info,$12.00
ink,$29.00
institute,$21.00
insure,$47.00
international,$21.00
investments,$94.00
io,$39.00
irish,$36.00
it,$15.00
jewelry,$51.00
jp,$90.00
juegos,$13.00
kaufen,$30.00
kim,$15.00
kitchen,$46.00
kiwi,$32.00
land,$32.00
lease,$47.00
legal,$47.00
lgbt,$43.00
life,$29.00
lighting,$21.00
limited,$29.00
limo,$35.00
link,$10.00
live,$23.00
loan,$31.00
loans,$94.00
lol,$31.00
maison,$49.00
management,$21.00
marketing,$32.00
mba,$31.00
me,$17.00
me.uk,$8.00
media,$29.00
memorial,$47.00
mobi,$12.00
moda,$22.00
money,$29.00
mortgage,$43.00
movie,$306.00
mx,$34.00
name,$9.00
net,$11.00
net.au,$15.00
net.nz,$24.00
network,$19.00
news,$23.00
ninja,$18.00
nl,$10.00
onl,$15.00
online,$39.00
org,$12.00
org.nz,$24.00
org.uk,$9.00
partners,$49.00
parts,$29.00
photo,$30.00
photography,$21.00
photos,$21.00
pics,$20.00
pictures,$10.00
pink,$15.00
pizza,$47.00
place,$29.00
plumbing,$46.00
plus,$31.00
poker,$43.00
porn,$88.00
pro,$14.00
productions,$30.00
properties,$30.00
property,$29.00
pub,$22.00
qa,$64.00*
qpon,$15.00
recipes,$35.00
red,$15.00
reise,$101.00
reisen,$19.00
rentals,$30.00
repair,$32.00
report,$19.00
republican,$29.00
restaurant,$47.00
reviews,$22.00
rip,$17.00
rocks,$12.00
ru,$36.00
ruhr,$30.00
run,$20.00
sale,$29.00
sarl,$29.00
school,$29.00
schule,$19.00
se,$23.00
services,$29.00
sex,$95.00
sexy,$22.00
sg,$47.00*
sh,$48.00
shiksha,$16.00
shoes,$46.00
show,$31.00
singles,$30.00
soccer,$20.00
social,$32.00
solar,$46.00
solutions,$25.00
studio,$23.00
style,$29.00
sucks,$282.00
supplies,$19.00
supply,$19.00
support,$21.00
surgery,$47.00
systems,$21.00
tattoo,$30.00
tax,$47.00
taxi,$51.00
team,$31.00
technology,$21.00
tennis,$47.00
theater,$51.00
tienda,$50.00
tips,$21.00
tires,$94.00
today,$21.00
tools,$29.00
tours,$51.00
town,$29.00
toys,$46.00
trade,$29.00
training,$27.00
tv,$32.00
uk,$9.00
university,$47.00
uno,$30.00
us,$15.00
vacations,$35.00
vc,$33.00
vegas,$57.00
ventures,$35.00
vg,$35.00
viajes,$49.00
video,$22.00
villas,$35.00
vision,$29.00
voyage,$50.00
watch,$37.00
website,$23.00
wien,$29.00
wiki,$30.00
works,$30.00
world,$29.00
wtf,$29.00
xyz,$12.00
zone,$32.00
`

func init() {
	r := csv.NewReader(strings.NewReader(priceList))

	rows, err := r.ReadAll()
	if err != nil {
		log.WithError(err).Debug("reading price list")
		return
	}

	for _, row := range rows {
		name := row[0]
		price := row[1]
		tlds[name] = price
	}
}
