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
[Value]
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
Value
lpk <- App Value -> (Value -> App Value) -> Maybe Value -> App Value
forall b a. b -> (a -> b) -> Maybe a -> b
maybe App Value
getLastPrekey Value -> App Value
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AddClient
args.lastPrekey
[Pair] -> App [Pair]
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
[ String
"prekeys" String -> [Value] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [Value]
pks,
String
"lastkey" String -> Value -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Value
lpk,
String
"type" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= AddClient
args.ctype,
String
"label" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= AddClient
args.clabel,
String
"model" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= AddClient
args.model,
String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= AddClient
args.password,
String
"capabilities" String -> Maybe [String] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= AddClient
args.acapabilities
]