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