{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE TemplateHaskell            #-}

module CoinbasePro.WebSocketFeed.Channel.Full.Done
    ( Done (..)
    ) where

import           Data.Aeson        (FromJSON, parseJSON)
import           Data.Aeson.Casing (snakeCase)
import           Data.Aeson.TH     (defaultOptions, deriveJSON,
                                    fieldLabelModifier)
import           Data.Text         (Text)
import           Data.Time.Clock   (UTCTime)

import           CoinbasePro.Types (OrderId, Price, ProductId, ProfileId,
                                    Sequence, Side, Size, UserId)


type Reason = Text

newtype RemainingSize = RemainingSize { RemainingSize -> Maybe Size
unRemainingSize :: Maybe Size }
    deriving (RemainingSize -> RemainingSize -> Bool
(RemainingSize -> RemainingSize -> Bool)
-> (RemainingSize -> RemainingSize -> Bool) -> Eq RemainingSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RemainingSize -> RemainingSize -> Bool
$c/= :: RemainingSize -> RemainingSize -> Bool
== :: RemainingSize -> RemainingSize -> Bool
$c== :: RemainingSize -> RemainingSize -> Bool
Eq, Eq RemainingSize
Eq RemainingSize
-> (RemainingSize -> RemainingSize -> Ordering)
-> (RemainingSize -> RemainingSize -> Bool)
-> (RemainingSize -> RemainingSize -> Bool)
-> (RemainingSize -> RemainingSize -> Bool)
-> (RemainingSize -> RemainingSize -> Bool)
-> (RemainingSize -> RemainingSize -> RemainingSize)
-> (RemainingSize -> RemainingSize -> RemainingSize)
-> Ord RemainingSize
RemainingSize -> RemainingSize -> Bool
RemainingSize -> RemainingSize -> Ordering
RemainingSize -> RemainingSize -> RemainingSize
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 :: RemainingSize -> RemainingSize -> RemainingSize
$cmin :: RemainingSize -> RemainingSize -> RemainingSize
max :: RemainingSize -> RemainingSize -> RemainingSize
$cmax :: RemainingSize -> RemainingSize -> RemainingSize
>= :: RemainingSize -> RemainingSize -> Bool
$c>= :: RemainingSize -> RemainingSize -> Bool
> :: RemainingSize -> RemainingSize -> Bool
$c> :: RemainingSize -> RemainingSize -> Bool
<= :: RemainingSize -> RemainingSize -> Bool
$c<= :: RemainingSize -> RemainingSize -> Bool
< :: RemainingSize -> RemainingSize -> Bool
$c< :: RemainingSize -> RemainingSize -> Bool
compare :: RemainingSize -> RemainingSize -> Ordering
$ccompare :: RemainingSize -> RemainingSize -> Ordering
$cp1Ord :: Eq RemainingSize
Ord, Int -> RemainingSize -> ShowS
[RemainingSize] -> ShowS
RemainingSize -> String
(Int -> RemainingSize -> ShowS)
-> (RemainingSize -> String)
-> ([RemainingSize] -> ShowS)
-> Show RemainingSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RemainingSize] -> ShowS
$cshowList :: [RemainingSize] -> ShowS
show :: RemainingSize -> String
$cshow :: RemainingSize -> String
showsPrec :: Int -> RemainingSize -> ShowS
$cshowsPrec :: Int -> RemainingSize -> ShowS
Show)


instance FromJSON RemainingSize where
    parseJSON :: Value -> Parser RemainingSize
parseJSON = (Maybe Size -> RemainingSize
RemainingSize (Maybe Size -> RemainingSize)
-> Parser (Maybe Size) -> Parser RemainingSize
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (Parser (Maybe Size) -> Parser RemainingSize)
-> (Value -> Parser (Maybe Size)) -> Value -> Parser RemainingSize
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Parser (Maybe Size)
forall a. FromJSON a => Value -> Parser a
parseJSON


data Done = Done
    { Done -> UTCTime
time          :: UTCTime
    , Done -> ProductId
productId     :: ProductId
    , Done -> Int
sequence      :: Sequence
    , Done -> Maybe Price
price         :: Maybe Price
    , Done -> OrderId
orderId       :: OrderId
    , Done -> Reason
reason        :: Reason
    , Done -> Side
side          :: Side
    , Done -> Maybe Size
remainingSize :: Maybe Size
    , Done -> Maybe Reason
userId        :: Maybe UserId
    , Done -> Maybe Reason
profileId     :: Maybe ProfileId
    } deriving (Done -> Done -> Bool
(Done -> Done -> Bool) -> (Done -> Done -> Bool) -> Eq Done
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Done -> Done -> Bool
$c/= :: Done -> Done -> Bool
== :: Done -> Done -> Bool
$c== :: Done -> Done -> Bool
Eq, Eq Done
Eq Done
-> (Done -> Done -> Ordering)
-> (Done -> Done -> Bool)
-> (Done -> Done -> Bool)
-> (Done -> Done -> Bool)
-> (Done -> Done -> Bool)
-> (Done -> Done -> Done)
-> (Done -> Done -> Done)
-> Ord Done
Done -> Done -> Bool
Done -> Done -> Ordering
Done -> Done -> Done
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 :: Done -> Done -> Done
$cmin :: Done -> Done -> Done
max :: Done -> Done -> Done
$cmax :: Done -> Done -> Done
>= :: Done -> Done -> Bool
$c>= :: Done -> Done -> Bool
> :: Done -> Done -> Bool
$c> :: Done -> Done -> Bool
<= :: Done -> Done -> Bool
$c<= :: Done -> Done -> Bool
< :: Done -> Done -> Bool
$c< :: Done -> Done -> Bool
compare :: Done -> Done -> Ordering
$ccompare :: Done -> Done -> Ordering
$cp1Ord :: Eq Done
Ord, Int -> Done -> ShowS
[Done] -> ShowS
Done -> String
(Int -> Done -> ShowS)
-> (Done -> String) -> ([Done] -> ShowS) -> Show Done
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Done] -> ShowS
$cshowList :: [Done] -> ShowS
show :: Done -> String
$cshow :: Done -> String
showsPrec :: Int -> Done -> ShowS
$cshowsPrec :: Int -> Done -> ShowS
Show)


deriveJSON defaultOptions {fieldLabelModifier = snakeCase} ''Done