module API.BrigCommon where
import API.Common
import Data.Aeson.Types (Pair)
import Data.Maybe
import Testlib.Prelude as Prelude
data AddClient = AddClient
{ AddClient -> String
ctype :: String,
AddClient -> Bool
internal :: Bool,
AddClient -> String
clabel :: String,
AddClient -> String
model :: String,
AddClient -> Maybe [Value]
prekeys :: Maybe [Value],
AddClient -> Maybe Value
lastPrekey :: Maybe Value,
AddClient -> String
password :: String,
AddClient -> Maybe [String]
acapabilities :: Maybe [String]
}
instance Default AddClient where
def :: AddClient
def =
AddClient
{ ctype :: String
ctype = String
"permanent",
internal :: Bool
internal = Bool
False,
clabel :: String
clabel = String
"Test Device",
model :: String
model = String
"Test Model",
prekeys :: Maybe [Value]
prekeys = Maybe [Value]
forall a. Maybe a
Nothing,
lastPrekey :: Maybe Value
lastPrekey = Maybe Value
forall a. Maybe a
Nothing,
password :: String
password = String
defPassword,
acapabilities :: Maybe [String]
acapabilities = [String] -> Maybe [String]
forall a. a -> Maybe a
Just [String
"legalhold-implicit-consent"]
}
mkAddClientValue :: AddClient -> App [Pair]
mkAddClientValue :: AddClient -> App [Pair]
mkAddClientValue AddClient
args = do
pks <- App [Value]
-> ([Value] -> App [Value]) -> Maybe [Value] -> App [Value]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((Value -> [Value]) -> App Value -> App [Value]
forall a b. (a -> b) -> App a -> App b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Value -> [Value]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure App Value
getPrekey) [Value] -> App [Value]
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AddClient
args.prekeys
lpk <- maybe getLastPrekey pure args.lastPrekey
pure
[ "prekeys" .= pks,
"lastkey" .= lpk,
"type" .= args.ctype,
"label" .= args.clabel,
"model" .= args.model,
"password" .= args.password,
"capabilities" .= args.acapabilities
]