module TD.Data.LogTags
(LogTags(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data LogTags
= LogTags
{ LogTags -> Maybe [Text]
tags :: Maybe [T.Text]
}
deriving (LogTags -> LogTags -> Bool
(LogTags -> LogTags -> Bool)
-> (LogTags -> LogTags -> Bool) -> Eq LogTags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LogTags -> LogTags -> Bool
== :: LogTags -> LogTags -> Bool
$c/= :: LogTags -> LogTags -> Bool
/= :: LogTags -> LogTags -> Bool
Eq, Int -> LogTags -> ShowS
[LogTags] -> ShowS
LogTags -> String
(Int -> LogTags -> ShowS)
-> (LogTags -> String) -> ([LogTags] -> ShowS) -> Show LogTags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LogTags -> ShowS
showsPrec :: Int -> LogTags -> ShowS
$cshow :: LogTags -> String
show :: LogTags -> String
$cshowList :: [LogTags] -> ShowS
showList :: [LogTags] -> ShowS
Show)
instance I.ShortShow LogTags where
shortShow :: LogTags -> String
shortShow LogTags
{ tags :: LogTags -> Maybe [Text]
tags = Maybe [Text]
tags_
}
= String
"LogTags"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"tags" String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
tags_
]
instance AT.FromJSON LogTags where
parseJSON :: Value -> Parser LogTags
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
"logTags" -> Value -> Parser LogTags
parseLogTags Value
v
String
_ -> Parser LogTags
forall a. Monoid a => a
mempty
where
parseLogTags :: A.Value -> AT.Parser LogTags
parseLogTags :: Value -> Parser LogTags
parseLogTags = String -> (Object -> Parser LogTags) -> Value -> Parser LogTags
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LogTags" ((Object -> Parser LogTags) -> Value -> Parser LogTags)
-> (Object -> Parser LogTags) -> Value -> Parser LogTags
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [Text]
tags_ <- Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"tags"
LogTags -> Parser LogTags
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LogTags -> Parser LogTags) -> LogTags -> Parser LogTags
forall a b. (a -> b) -> a -> b
$ LogTags
{ tags :: Maybe [Text]
tags = Maybe [Text]
tags_
}
parseJSON Value
_ = Parser LogTags
forall a. Monoid a => a
mempty