{-# LANGUAGE OverloadedStrings #-}

module CoinbasePro.WebSocketFeed.Channel.Heartbeat
    ( Heartbeat (..)
    )where

import           Data.Aeson      (FromJSON (..), withObject, (.:))
import           Data.Text       (Text)
import           Data.Time.Clock (UTCTime)


data Heartbeat = Heartbeat
    { Heartbeat -> Int
sequence    :: Int
    , Heartbeat -> Int
lastTradeId :: Int
    , Heartbeat -> Text
productId   :: Text
    , Heartbeat -> UTCTime
time        :: UTCTime
    } deriving (Heartbeat -> Heartbeat -> Bool
(Heartbeat -> Heartbeat -> Bool)
-> (Heartbeat -> Heartbeat -> Bool) -> Eq Heartbeat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Heartbeat -> Heartbeat -> Bool
$c/= :: Heartbeat -> Heartbeat -> Bool
== :: Heartbeat -> Heartbeat -> Bool
$c== :: Heartbeat -> Heartbeat -> Bool
Eq, Eq Heartbeat
Eq Heartbeat
-> (Heartbeat -> Heartbeat -> Ordering)
-> (Heartbeat -> Heartbeat -> Bool)
-> (Heartbeat -> Heartbeat -> Bool)
-> (Heartbeat -> Heartbeat -> Bool)
-> (Heartbeat -> Heartbeat -> Bool)
-> (Heartbeat -> Heartbeat -> Heartbeat)
-> (Heartbeat -> Heartbeat -> Heartbeat)
-> Ord Heartbeat
Heartbeat -> Heartbeat -> Bool
Heartbeat -> Heartbeat -> Ordering
Heartbeat -> Heartbeat -> Heartbeat
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Heartbeat -> Heartbeat -> Heartbeat
$cmin :: Heartbeat -> Heartbeat -> Heartbeat
max :: Heartbeat -> Heartbeat -> Heartbeat
$cmax :: Heartbeat -> Heartbeat -> Heartbeat
>= :: Heartbeat -> Heartbeat -> Bool
$c>= :: Heartbeat -> Heartbeat -> Bool
> :: Heartbeat -> Heartbeat -> Bool
$c> :: Heartbeat -> Heartbeat -> Bool
<= :: Heartbeat -> Heartbeat -> Bool
$c<= :: Heartbeat -> Heartbeat -> Bool
< :: Heartbeat -> Heartbeat -> Bool
$c< :: Heartbeat -> Heartbeat -> Bool
compare :: Heartbeat -> Heartbeat -> Ordering
$ccompare :: Heartbeat -> Heartbeat -> Ordering
$cp1Ord :: Eq Heartbeat
Ord, Int -> Heartbeat -> ShowS
[Heartbeat] -> ShowS
Heartbeat -> String
(Int -> Heartbeat -> ShowS)
-> (Heartbeat -> String)
-> ([Heartbeat] -> ShowS)
-> Show Heartbeat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Heartbeat] -> ShowS
$cshowList :: [Heartbeat] -> ShowS
show :: Heartbeat -> String
$cshow :: Heartbeat -> String
showsPrec :: Int -> Heartbeat -> ShowS
$cshowsPrec :: Int -> Heartbeat -> ShowS
Show)


instance FromJSON Heartbeat where
    parseJSON :: Value -> Parser Heartbeat
parseJSON = String -> (Object -> Parser Heartbeat) -> Value -> Parser Heartbeat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"heartbeat" ((Object -> Parser Heartbeat) -> Value -> Parser Heartbeat)
-> (Object -> Parser Heartbeat) -> Value -> Parser Heartbeat
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      Int -> Int -> Text -> UTCTime -> Heartbeat
Heartbeat (Int -> Int -> Text -> UTCTime -> Heartbeat)
-> Parser Int -> Parser (Int -> Text -> UTCTime -> Heartbeat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        Object
o Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"sequence" Parser (Int -> Text -> UTCTime -> Heartbeat)
-> Parser Int -> Parser (Text -> UTCTime -> Heartbeat)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Object
o Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"last_trade_id" Parser (Text -> UTCTime -> Heartbeat)
-> Parser Text -> Parser (UTCTime -> Heartbeat)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"product_id" Parser (UTCTime -> Heartbeat) -> Parser UTCTime -> Parser Heartbeat
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Object
o Object -> Text -> Parser UTCTime
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"time"