{-# LANGUAGE TemplateHaskell #-}

module Zero.GDAX.Internal
  (
    ProductTicker(..)
  , defaultProductTicker
  ) where

import           GHC.Generics
import           Data.Text (Text)
import           Data.Aeson

------------------------------------------------------------------------------

data ProductTicker = ProductTicker
  { pt_tradeId :: Integer
  , pt_price :: Text
  , pt_size :: Text
  , pt_bid :: Text
  , pt_ask :: Text
  , pt_volume :: Text
  , pt_time :: Text
  } deriving (Show, Generic)

defaultProductTicker =
  ProductTicker 0 "0.0" "0.0" "0.0" "0.0" "0.0" "TIMESTAMP"

instance FromJSON ProductTicker where
  parseJSON = withObject "ProductTicker" $ \v -> ProductTicker
    <$> v .: "trade_id"
    <*> v .: "price"
    <*> v .: "size"
    <*> v .: "bid"
    <*> v .: "ask"
    <*> v .: "volume"
    <*> v .: "time"

instance ToJSON ProductTicker where
  toJSON (ProductTicker a1 a2 a3 a4 a5 a6 a7) =
    object [
      "trade_id" .= a1
    , "price" .= a2
    , "size" .= a3
    , "bid" .= a4
    , "ask" .= a5
    , "volume" .= a6
    , "time" .= a7
    ]
