module TD.Query.SetUsername
  (SetUsername(..)
  ) 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

-- | Changes the editable username of the current user. Returns 'TD.Data.Ok.Ok'
data SetUsername
  = SetUsername
    { SetUsername -> Maybe Text
username :: Maybe T.Text -- ^ The new value of the username. Use an empty string to remove the username. The username can't be completely removed if there is another active or disabled username
    }
  deriving (SetUsername -> SetUsername -> Bool
(SetUsername -> SetUsername -> Bool)
-> (SetUsername -> SetUsername -> Bool) -> Eq SetUsername
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetUsername -> SetUsername -> Bool
== :: SetUsername -> SetUsername -> Bool
$c/= :: SetUsername -> SetUsername -> Bool
/= :: SetUsername -> SetUsername -> Bool
Eq, Int -> SetUsername -> ShowS
[SetUsername] -> ShowS
SetUsername -> String
(Int -> SetUsername -> ShowS)
-> (SetUsername -> String)
-> ([SetUsername] -> ShowS)
-> Show SetUsername
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetUsername -> ShowS
showsPrec :: Int -> SetUsername -> ShowS
$cshow :: SetUsername -> String
show :: SetUsername -> String
$cshowList :: [SetUsername] -> ShowS
showList :: [SetUsername] -> ShowS
Show)

instance I.ShortShow SetUsername where
  shortShow :: SetUsername -> String
shortShow
    SetUsername
      { username :: SetUsername -> Maybe Text
username = Maybe Text
username_
      }
        = String
"SetUsername"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"username" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
username_
          ]

instance AT.ToJSON SetUsername where
  toJSON :: SetUsername -> Value
toJSON
    SetUsername
      { username :: SetUsername -> Maybe Text
username = Maybe Text
username_
      }
        = [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
"setUsername"
          , Key
"username" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
username_
          ]