module TD.Data.ChatPosition
(ChatPosition(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.ChatList as ChatList
import qualified TD.Data.ChatSource as ChatSource
data ChatPosition
= ChatPosition
{ ChatPosition -> Maybe ChatList
list :: Maybe ChatList.ChatList
, ChatPosition -> Maybe Int
order :: Maybe Int
, ChatPosition -> Maybe Bool
is_pinned :: Maybe Bool
, ChatPosition -> Maybe ChatSource
source :: Maybe ChatSource.ChatSource
}
deriving (ChatPosition -> ChatPosition -> Bool
(ChatPosition -> ChatPosition -> Bool)
-> (ChatPosition -> ChatPosition -> Bool) -> Eq ChatPosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatPosition -> ChatPosition -> Bool
== :: ChatPosition -> ChatPosition -> Bool
$c/= :: ChatPosition -> ChatPosition -> Bool
/= :: ChatPosition -> ChatPosition -> Bool
Eq, Int -> ChatPosition -> ShowS
[ChatPosition] -> ShowS
ChatPosition -> String
(Int -> ChatPosition -> ShowS)
-> (ChatPosition -> String)
-> ([ChatPosition] -> ShowS)
-> Show ChatPosition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatPosition -> ShowS
showsPrec :: Int -> ChatPosition -> ShowS
$cshow :: ChatPosition -> String
show :: ChatPosition -> String
$cshowList :: [ChatPosition] -> ShowS
showList :: [ChatPosition] -> ShowS
Show)
instance I.ShortShow ChatPosition where
shortShow :: ChatPosition -> String
shortShow ChatPosition
{ list :: ChatPosition -> Maybe ChatList
list = Maybe ChatList
list_
, order :: ChatPosition -> Maybe Int
order = Maybe Int
order_
, is_pinned :: ChatPosition -> Maybe Bool
is_pinned = Maybe Bool
is_pinned_
, source :: ChatPosition -> Maybe ChatSource
source = Maybe ChatSource
source_
}
= String
"ChatPosition"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"list" String -> Maybe ChatList -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatList
list_
, String
"order" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
order_
, String
"is_pinned" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_pinned_
, String
"source" String -> Maybe ChatSource -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatSource
source_
]
instance AT.FromJSON ChatPosition where
parseJSON :: Value -> Parser ChatPosition
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"chatPosition" -> Value -> Parser ChatPosition
parseChatPosition Value
v
String
_ -> Parser ChatPosition
forall a. Monoid a => a
mempty
where
parseChatPosition :: A.Value -> AT.Parser ChatPosition
parseChatPosition :: Value -> Parser ChatPosition
parseChatPosition = String
-> (Object -> Parser ChatPosition) -> Value -> Parser ChatPosition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatPosition" ((Object -> Parser ChatPosition) -> Value -> Parser ChatPosition)
-> (Object -> Parser ChatPosition) -> Value -> Parser ChatPosition
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ChatList
list_ <- Object
o Object -> Key -> Parser (Maybe ChatList)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"list"
Maybe Int
order_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"order"
Maybe Bool
is_pinned_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_pinned"
Maybe ChatSource
source_ <- Object
o Object -> Key -> Parser (Maybe ChatSource)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"source"
ChatPosition -> Parser ChatPosition
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatPosition -> Parser ChatPosition)
-> ChatPosition -> Parser ChatPosition
forall a b. (a -> b) -> a -> b
$ ChatPosition
{ list :: Maybe ChatList
list = Maybe ChatList
list_
, order :: Maybe Int
order = Maybe Int
order_
, is_pinned :: Maybe Bool
is_pinned = Maybe Bool
is_pinned_
, source :: Maybe ChatSource
source = Maybe ChatSource
source_
}
parseJSON Value
_ = Parser ChatPosition
forall a. Monoid a => a
mempty