module TD.Query.SetDatabaseEncryptionKey
  (SetDatabaseEncryptionKey(..)
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.ByteString as BS

-- | Changes the database encryption key. Usually the encryption key is never changed and is stored in some OS keychain. Returns 'TD.Data.Ok.Ok'
data SetDatabaseEncryptionKey
  = SetDatabaseEncryptionKey
    { SetDatabaseEncryptionKey -> Maybe ByteString
new_encryption_key :: Maybe BS.ByteString -- ^ New encryption key
    }
  deriving (SetDatabaseEncryptionKey -> SetDatabaseEncryptionKey -> Bool
(SetDatabaseEncryptionKey -> SetDatabaseEncryptionKey -> Bool)
-> (SetDatabaseEncryptionKey -> SetDatabaseEncryptionKey -> Bool)
-> Eq SetDatabaseEncryptionKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetDatabaseEncryptionKey -> SetDatabaseEncryptionKey -> Bool
== :: SetDatabaseEncryptionKey -> SetDatabaseEncryptionKey -> Bool
$c/= :: SetDatabaseEncryptionKey -> SetDatabaseEncryptionKey -> Bool
/= :: SetDatabaseEncryptionKey -> SetDatabaseEncryptionKey -> Bool
Eq, Int -> SetDatabaseEncryptionKey -> ShowS
[SetDatabaseEncryptionKey] -> ShowS
SetDatabaseEncryptionKey -> String
(Int -> SetDatabaseEncryptionKey -> ShowS)
-> (SetDatabaseEncryptionKey -> String)
-> ([SetDatabaseEncryptionKey] -> ShowS)
-> Show SetDatabaseEncryptionKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetDatabaseEncryptionKey -> ShowS
showsPrec :: Int -> SetDatabaseEncryptionKey -> ShowS
$cshow :: SetDatabaseEncryptionKey -> String
show :: SetDatabaseEncryptionKey -> String
$cshowList :: [SetDatabaseEncryptionKey] -> ShowS
showList :: [SetDatabaseEncryptionKey] -> ShowS
Show)

instance I.ShortShow SetDatabaseEncryptionKey where
  shortShow :: SetDatabaseEncryptionKey -> String
shortShow
    SetDatabaseEncryptionKey
      { new_encryption_key :: SetDatabaseEncryptionKey -> Maybe ByteString
new_encryption_key = Maybe ByteString
new_encryption_key_
      }
        = String
"SetDatabaseEncryptionKey"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"new_encryption_key" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
new_encryption_key_
          ]

instance AT.ToJSON SetDatabaseEncryptionKey where
  toJSON :: SetDatabaseEncryptionKey -> Value
toJSON
    SetDatabaseEncryptionKey
      { new_encryption_key :: SetDatabaseEncryptionKey -> Maybe ByteString
new_encryption_key = Maybe ByteString
new_encryption_key_
      }
        = [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
"setDatabaseEncryptionKey"
          , Key
"new_encryption_key" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (ByteString -> Value) -> Maybe ByteString -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Value
I.writeBytes  Maybe ByteString
new_encryption_key_
          ]