summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Model/Route.hs
blob: 1a621692e4d2f359b678eadf048f325246ee3a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}

module SpaceTraders.Model.Route
  ( Route(..)
  , RouteEndpoint(..)
  ) where

import Data.Aeson
import Data.Time
import GHC.Generics
import qualified Data.Text as T

data Route = Route { arrival :: UTCTime
                   , departureTime :: UTCTime
                   , destination :: RouteEndpoint
                   , origin :: RouteEndpoint
                   } deriving (FromJSON, Generic, Show, ToJSON)

data RouteEndpoint = RouteEndpoint { routeEndpointType :: T.Text
                                   , symbol :: T.Text
                                   , systemSymbol :: T.Text
                                   , x :: Int
                                   , y :: Int
                                   } deriving (Generic, Show)
instance FromJSON RouteEndpoint where
  parseJSON = withObject "RouteEndpoint" $ \o ->
    RouteEndpoint <$> o .: "type"
                  <*> o .: "symbol"
                  <*> o .: "systemSymbol"
                  <*> o .: "x"
                  <*> o .: "y"
instance ToJSON RouteEndpoint where
  toJSON (RouteEndpoint t s ss xx yy) = object [ "type" .= t
                                               , "symbol" .= s
                                               , "systemSymbol" .= ss
                                               , "x" .= xx
                                               , "y" .= yy ]