module TD.Data.Usernames
(Usernames(..)) 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 Usernames
= Usernames
{ Usernames -> Maybe [Text]
active_usernames :: Maybe [T.Text]
, Usernames -> Maybe [Text]
disabled_usernames :: Maybe [T.Text]
, Usernames -> Maybe Text
editable_username :: Maybe T.Text
}
deriving (Usernames -> Usernames -> Bool
(Usernames -> Usernames -> Bool)
-> (Usernames -> Usernames -> Bool) -> Eq Usernames
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Usernames -> Usernames -> Bool
== :: Usernames -> Usernames -> Bool
$c/= :: Usernames -> Usernames -> Bool
/= :: Usernames -> Usernames -> Bool
Eq, Int -> Usernames -> ShowS
[Usernames] -> ShowS
Usernames -> String
(Int -> Usernames -> ShowS)
-> (Usernames -> String)
-> ([Usernames] -> ShowS)
-> Show Usernames
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Usernames -> ShowS
showsPrec :: Int -> Usernames -> ShowS
$cshow :: Usernames -> String
show :: Usernames -> String
$cshowList :: [Usernames] -> ShowS
showList :: [Usernames] -> ShowS
Show)
instance I.ShortShow Usernames where
shortShow :: Usernames -> String
shortShow Usernames
{ active_usernames :: Usernames -> Maybe [Text]
active_usernames = Maybe [Text]
active_usernames_
, disabled_usernames :: Usernames -> Maybe [Text]
disabled_usernames = Maybe [Text]
disabled_usernames_
, editable_username :: Usernames -> Maybe Text
editable_username = Maybe Text
editable_username_
}
= String
"Usernames"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"active_usernames" String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
active_usernames_
, String
"disabled_usernames" String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
disabled_usernames_
, String
"editable_username" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
editable_username_
]
instance AT.FromJSON Usernames where
parseJSON :: Value -> Parser Usernames
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
"usernames" -> Value -> Parser Usernames
parseUsernames Value
v
String
_ -> Parser Usernames
forall a. Monoid a => a
mempty
where
parseUsernames :: A.Value -> AT.Parser Usernames
parseUsernames :: Value -> Parser Usernames
parseUsernames = String -> (Object -> Parser Usernames) -> Value -> Parser Usernames
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Usernames" ((Object -> Parser Usernames) -> Value -> Parser Usernames)
-> (Object -> Parser Usernames) -> Value -> Parser Usernames
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [Text]
active_usernames_ <- Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"active_usernames"
Maybe [Text]
disabled_usernames_ <- Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"disabled_usernames"
Maybe Text
editable_username_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"editable_username"
Usernames -> Parser Usernames
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Usernames -> Parser Usernames) -> Usernames -> Parser Usernames
forall a b. (a -> b) -> a -> b
$ Usernames
{ active_usernames :: Maybe [Text]
active_usernames = Maybe [Text]
active_usernames_
, disabled_usernames :: Maybe [Text]
disabled_usernames = Maybe [Text]
disabled_usernames_
, editable_username :: Maybe Text
editable_username = Maybe Text
editable_username_
}
parseJSON Value
_ = Parser Usernames
forall a. Monoid a => a
mempty