module TD.Data.MessageCalendar
(MessageCalendar(..)) 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.MessageCalendarDay as MessageCalendarDay
data MessageCalendar
= MessageCalendar
{ MessageCalendar -> Maybe Int
total_count :: Maybe Int
, MessageCalendar -> Maybe [MessageCalendarDay]
days :: Maybe [MessageCalendarDay.MessageCalendarDay]
}
deriving (MessageCalendar -> MessageCalendar -> Bool
(MessageCalendar -> MessageCalendar -> Bool)
-> (MessageCalendar -> MessageCalendar -> Bool)
-> Eq MessageCalendar
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageCalendar -> MessageCalendar -> Bool
== :: MessageCalendar -> MessageCalendar -> Bool
$c/= :: MessageCalendar -> MessageCalendar -> Bool
/= :: MessageCalendar -> MessageCalendar -> Bool
Eq, Int -> MessageCalendar -> ShowS
[MessageCalendar] -> ShowS
MessageCalendar -> String
(Int -> MessageCalendar -> ShowS)
-> (MessageCalendar -> String)
-> ([MessageCalendar] -> ShowS)
-> Show MessageCalendar
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageCalendar -> ShowS
showsPrec :: Int -> MessageCalendar -> ShowS
$cshow :: MessageCalendar -> String
show :: MessageCalendar -> String
$cshowList :: [MessageCalendar] -> ShowS
showList :: [MessageCalendar] -> ShowS
Show)
instance I.ShortShow MessageCalendar where
shortShow :: MessageCalendar -> String
shortShow MessageCalendar
{ total_count :: MessageCalendar -> Maybe Int
total_count = Maybe Int
total_count_
, days :: MessageCalendar -> Maybe [MessageCalendarDay]
days = Maybe [MessageCalendarDay]
days_
}
= String
"MessageCalendar"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"total_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
, String
"days" String -> Maybe [MessageCalendarDay] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [MessageCalendarDay]
days_
]
instance AT.FromJSON MessageCalendar where
parseJSON :: Value -> Parser MessageCalendar
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
"messageCalendar" -> Value -> Parser MessageCalendar
parseMessageCalendar Value
v
String
_ -> Parser MessageCalendar
forall a. Monoid a => a
mempty
where
parseMessageCalendar :: A.Value -> AT.Parser MessageCalendar
parseMessageCalendar :: Value -> Parser MessageCalendar
parseMessageCalendar = String
-> (Object -> Parser MessageCalendar)
-> Value
-> Parser MessageCalendar
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageCalendar" ((Object -> Parser MessageCalendar)
-> Value -> Parser MessageCalendar)
-> (Object -> Parser MessageCalendar)
-> Value
-> Parser MessageCalendar
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
total_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"total_count"
Maybe [MessageCalendarDay]
days_ <- Object
o Object -> Key -> Parser (Maybe [MessageCalendarDay])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"days"
MessageCalendar -> Parser MessageCalendar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageCalendar -> Parser MessageCalendar)
-> MessageCalendar -> Parser MessageCalendar
forall a b. (a -> b) -> a -> b
$ MessageCalendar
{ total_count :: Maybe Int
total_count = Maybe Int
total_count_
, days :: Maybe [MessageCalendarDay]
days = Maybe [MessageCalendarDay]
days_
}
parseJSON Value
_ = Parser MessageCalendar
forall a. Monoid a => a
mempty