module City where

{- 
  Cidade{
	String            nome
	Tupla(Int, Int)   ponto
    Int               precoHotel
    
  }
    		
-}
data City = City [Char] (Int, Int) Int deriving (Eq, Show)

-- distancia entre duas cidades
cityDistance :: City -> City -> Float
cityDistance (City _ (x1,y1) _) (City _ (x2,y2) _) = sqrt( fromIntegral((x1-x2)^2+(y1-y2)^2) )

-- get custo hotel
getCityCost :: City -> Int
getCityCost (City _ _ x) = x

-- get nome da cidade
getCityName :: City -> [Char]
getCityName (City x _ _) = x

-- set nome da cidade
setNameCity :: [[Char]] -> [Char]
setNameCity [] = []
setNameCity xs = head xs 

-- set coordenada X
setCoordinateX :: [Char] -> [Char]
setCoordinateX (x:xs) | x/=' ' = x:setCoordinateX xs
                      | x==' ' = []

-- set coordenada Y
setCoordinateY :: [Char] -> [Char]
setCoordinateY (x:xs) | x/=' ' = setCoordinateY xs
                      | x==' ' = xs

-- set coordenada da cidade
setCoordinateCity :: [[Char]] -> (Int,Int)
setCoordinateCity [] = (0,0) -- []
setCoordinateCity xs = (read(setCoordinateX point)::Int, read(setCoordinateY point)::Int)
                  where point = head (drop 1 xs)

-- set custo da hospedagem da cidade
setCityCost :: [[Char]] -> Int
setCityCost [] = 0
setCityCost (x:xs) = (read(x)::Int)

-- cria lista de cidades
setCityList :: [[Char]] -> [[Char]]-> [City]
setCityList [] _ = []
setCityList _ [] = []
setCityList xs ys = (City name coordinate cost):setCityList (drop 2 xs) (drop 1 ys)
                  where name = setNameCity xs
                        coordinate = setCoordinateCity xs
                        cost = setCityCost ys
