module TD.Data.LogStream
(LogStream(..)) 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 LogStream
= LogStreamDefault
| LogStreamFile
{ LogStream -> Maybe Text
path :: Maybe T.Text
, LogStream -> Maybe Int
max_file_size :: Maybe Int
, LogStream -> Maybe Bool
redirect_stderr :: Maybe Bool
}
| LogStreamEmpty
deriving (LogStream -> LogStream -> Bool
(LogStream -> LogStream -> Bool)
-> (LogStream -> LogStream -> Bool) -> Eq LogStream
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LogStream -> LogStream -> Bool
== :: LogStream -> LogStream -> Bool
$c/= :: LogStream -> LogStream -> Bool
/= :: LogStream -> LogStream -> Bool
Eq, Int -> LogStream -> ShowS
[LogStream] -> ShowS
LogStream -> String
(Int -> LogStream -> ShowS)
-> (LogStream -> String)
-> ([LogStream] -> ShowS)
-> Show LogStream
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LogStream -> ShowS
showsPrec :: Int -> LogStream -> ShowS
$cshow :: LogStream -> String
show :: LogStream -> String
$cshowList :: [LogStream] -> ShowS
showList :: [LogStream] -> ShowS
Show)
instance I.ShortShow LogStream where
shortShow :: LogStream -> String
shortShow LogStream
LogStreamDefault
= String
"LogStreamDefault"
shortShow LogStreamFile
{ path :: LogStream -> Maybe Text
path = Maybe Text
path_
, max_file_size :: LogStream -> Maybe Int
max_file_size = Maybe Int
max_file_size_
, redirect_stderr :: LogStream -> Maybe Bool
redirect_stderr = Maybe Bool
redirect_stderr_
}
= String
"LogStreamFile"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"path" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
path_
, String
"max_file_size" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
max_file_size_
, String
"redirect_stderr" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
redirect_stderr_
]
shortShow LogStream
LogStreamEmpty
= String
"LogStreamEmpty"
instance AT.FromJSON LogStream where
parseJSON :: Value -> Parser LogStream
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
"logStreamDefault" -> LogStream -> Parser LogStream
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LogStream
LogStreamDefault
String
"logStreamFile" -> Value -> Parser LogStream
parseLogStreamFile Value
v
String
"logStreamEmpty" -> LogStream -> Parser LogStream
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LogStream
LogStreamEmpty
String
_ -> Parser LogStream
forall a. Monoid a => a
mempty
where
parseLogStreamFile :: A.Value -> AT.Parser LogStream
parseLogStreamFile :: Value -> Parser LogStream
parseLogStreamFile = String -> (Object -> Parser LogStream) -> Value -> Parser LogStream
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LogStreamFile" ((Object -> Parser LogStream) -> Value -> Parser LogStream)
-> (Object -> Parser LogStream) -> Value -> Parser LogStream
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
path_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"path"
Maybe Int
max_file_size_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"max_file_size"
Maybe Bool
redirect_stderr_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"redirect_stderr"
LogStream -> Parser LogStream
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LogStream -> Parser LogStream) -> LogStream -> Parser LogStream
forall a b. (a -> b) -> a -> b
$ LogStreamFile
{ path :: Maybe Text
path = Maybe Text
path_
, max_file_size :: Maybe Int
max_file_size = Maybe Int
max_file_size_
, redirect_stderr :: Maybe Bool
redirect_stderr = Maybe Bool
redirect_stderr_
}
parseJSON Value
_ = Parser LogStream
forall a. Monoid a => a
mempty
instance AT.ToJSON LogStream where
toJSON :: LogStream -> Value
toJSON LogStream
LogStreamDefault
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"logStreamDefault"
]
toJSON LogStreamFile
{ path :: LogStream -> Maybe Text
path = Maybe Text
path_
, max_file_size :: LogStream -> Maybe Int
max_file_size = Maybe Int
max_file_size_
, redirect_stderr :: LogStream -> Maybe Bool
redirect_stderr = Maybe Bool
redirect_stderr_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"logStreamFile"
, Key
"path" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
path_
, Key
"max_file_size" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
max_file_size_
, Key
"redirect_stderr" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
redirect_stderr_
]
toJSON LogStream
LogStreamEmpty
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"logStreamEmpty"
]