{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.QLDB.CreateLedger
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new ledger in your Amazon Web Services account in the current
-- Region.
module Amazonka.QLDB.CreateLedger
  ( -- * Creating a Request
    CreateLedger (..),
    newCreateLedger,

    -- * Request Lenses
    createLedger_deletionProtection,
    createLedger_kmsKey,
    createLedger_tags,
    createLedger_name,
    createLedger_permissionsMode,

    -- * Destructuring the Response
    CreateLedgerResponse (..),
    newCreateLedgerResponse,

    -- * Response Lenses
    createLedgerResponse_arn,
    createLedgerResponse_creationDateTime,
    createLedgerResponse_deletionProtection,
    createLedgerResponse_kmsKeyArn,
    createLedgerResponse_name,
    createLedgerResponse_permissionsMode,
    createLedgerResponse_state,
    createLedgerResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.QLDB.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateLedger' smart constructor.
data CreateLedger = CreateLedger'
  { -- | The flag that prevents a ledger from being deleted by any user. If not
    -- provided on ledger creation, this feature is enabled (@true@) by
    -- default.
    --
    -- If deletion protection is enabled, you must first disable it before you
    -- can delete the ledger. You can disable it by calling the @UpdateLedger@
    -- operation to set the flag to @false@.
    CreateLedger -> Maybe Bool
deletionProtection :: Prelude.Maybe Prelude.Bool,
    -- | The key in Key Management Service (KMS) to use for encryption of data at
    -- rest in the ledger. For more information, see
    -- <https://docs.aws.amazon.com/qldb/latest/developerguide/encryption-at-rest.html Encryption at rest>
    -- in the /Amazon QLDB Developer Guide/.
    --
    -- Use one of the following options to specify this parameter:
    --
    -- -   @AWS_OWNED_KMS_KEY@: Use an KMS key that is owned and managed by
    --     Amazon Web Services on your behalf.
    --
    -- -   __Undefined__: By default, use an Amazon Web Services owned KMS key.
    --
    -- -   __A valid symmetric customer managed KMS key__: Use the specified
    --     KMS key in your account that you create, own, and manage.
    --
    --     Amazon QLDB does not support asymmetric keys. For more information,
    --     see
    --     <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Using symmetric and asymmetric keys>
    --     in the /Key Management Service Developer Guide/.
    --
    -- To specify a customer managed KMS key, you can use its key ID, Amazon
    -- Resource Name (ARN), alias name, or alias ARN. When using an alias name,
    -- prefix it with @\"alias\/\"@. To specify a key in a different Amazon Web
    -- Services account, you must use the key ARN or alias ARN.
    --
    -- For example:
    --
    -- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
    --
    -- -   Key ARN:
    --     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
    --
    -- -   Alias name: @alias\/ExampleAlias@
    --
    -- -   Alias ARN: @arn:aws:kms:us-east-2:111122223333:alias\/ExampleAlias@
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id Key identifiers (KeyId)>
    -- in the /Key Management Service Developer Guide/.
    CreateLedger -> Maybe Text
kmsKey :: Prelude.Maybe Prelude.Text,
    -- | The key-value pairs to add as tags to the ledger that you want to
    -- create. Tag keys are case sensitive. Tag values are case sensitive and
    -- can be null.
    CreateLedger -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name of the ledger that you want to create. The name must be unique
    -- among all of the ledgers in your Amazon Web Services account in the
    -- current Region.
    --
    -- Naming constraints for ledger names are defined in
    -- <https://docs.aws.amazon.com/qldb/latest/developerguide/limits.html#limits.naming Quotas in Amazon QLDB>
    -- in the /Amazon QLDB Developer Guide/.
    CreateLedger -> Text
name :: Prelude.Text,
    -- | The permissions mode to assign to the ledger that you want to create.
    -- This parameter can have one of the following values:
    --
    -- -   @ALLOW_ALL@: A legacy permissions mode that enables access control
    --     with API-level granularity for ledgers.
    --
    --     This mode allows users who have the @SendCommand@ API permission for
    --     this ledger to run all PartiQL commands (hence, @ALLOW_ALL@) on any
    --     tables in the specified ledger. This mode disregards any table-level
    --     or command-level IAM permissions policies that you create for the
    --     ledger.
    --
    -- -   @STANDARD@: (/Recommended/) A permissions mode that enables access
    --     control with finer granularity for ledgers, tables, and PartiQL
    --     commands.
    --
    --     By default, this mode denies all user requests to run any PartiQL
    --     commands on any tables in this ledger. To allow PartiQL commands to
    --     run, you must create IAM permissions policies for specific table
    --     resources and PartiQL actions, in addition to the @SendCommand@ API
    --     permission for the ledger. For information, see
    --     <https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started-standard-mode.html Getting started with the standard permissions mode>
    --     in the /Amazon QLDB Developer Guide/.
    --
    -- We strongly recommend using the @STANDARD@ permissions mode to maximize
    -- the security of your ledger data.
    CreateLedger -> PermissionsMode
permissionsMode :: PermissionsMode
  }
  deriving (CreateLedger -> CreateLedger -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateLedger -> CreateLedger -> Bool
$c/= :: CreateLedger -> CreateLedger -> Bool
== :: CreateLedger -> CreateLedger -> Bool
$c== :: CreateLedger -> CreateLedger -> Bool
Prelude.Eq, ReadPrec [CreateLedger]
ReadPrec CreateLedger
Int -> ReadS CreateLedger
ReadS [CreateLedger]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateLedger]
$creadListPrec :: ReadPrec [CreateLedger]
readPrec :: ReadPrec CreateLedger
$creadPrec :: ReadPrec CreateLedger
readList :: ReadS [CreateLedger]
$creadList :: ReadS [CreateLedger]
readsPrec :: Int -> ReadS CreateLedger
$creadsPrec :: Int -> ReadS CreateLedger
Prelude.Read, Int -> CreateLedger -> ShowS
[CreateLedger] -> ShowS
CreateLedger -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateLedger] -> ShowS
$cshowList :: [CreateLedger] -> ShowS
show :: CreateLedger -> String
$cshow :: CreateLedger -> String
showsPrec :: Int -> CreateLedger -> ShowS
$cshowsPrec :: Int -> CreateLedger -> ShowS
Prelude.Show, forall x. Rep CreateLedger x -> CreateLedger
forall x. CreateLedger -> Rep CreateLedger x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateLedger x -> CreateLedger
$cfrom :: forall x. CreateLedger -> Rep CreateLedger x
Prelude.Generic)

-- |
-- Create a value of 'CreateLedger' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'deletionProtection', 'createLedger_deletionProtection' - The flag that prevents a ledger from being deleted by any user. If not
-- provided on ledger creation, this feature is enabled (@true@) by
-- default.
--
-- If deletion protection is enabled, you must first disable it before you
-- can delete the ledger. You can disable it by calling the @UpdateLedger@
-- operation to set the flag to @false@.
--
-- 'kmsKey', 'createLedger_kmsKey' - The key in Key Management Service (KMS) to use for encryption of data at
-- rest in the ledger. For more information, see
-- <https://docs.aws.amazon.com/qldb/latest/developerguide/encryption-at-rest.html Encryption at rest>
-- in the /Amazon QLDB Developer Guide/.
--
-- Use one of the following options to specify this parameter:
--
-- -   @AWS_OWNED_KMS_KEY@: Use an KMS key that is owned and managed by
--     Amazon Web Services on your behalf.
--
-- -   __Undefined__: By default, use an Amazon Web Services owned KMS key.
--
-- -   __A valid symmetric customer managed KMS key__: Use the specified
--     KMS key in your account that you create, own, and manage.
--
--     Amazon QLDB does not support asymmetric keys. For more information,
--     see
--     <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Using symmetric and asymmetric keys>
--     in the /Key Management Service Developer Guide/.
--
-- To specify a customer managed KMS key, you can use its key ID, Amazon
-- Resource Name (ARN), alias name, or alias ARN. When using an alias name,
-- prefix it with @\"alias\/\"@. To specify a key in a different Amazon Web
-- Services account, you must use the key ARN or alias ARN.
--
-- For example:
--
-- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Key ARN:
--     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Alias name: @alias\/ExampleAlias@
--
-- -   Alias ARN: @arn:aws:kms:us-east-2:111122223333:alias\/ExampleAlias@
--
-- For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id Key identifiers (KeyId)>
-- in the /Key Management Service Developer Guide/.
--
-- 'tags', 'createLedger_tags' - The key-value pairs to add as tags to the ledger that you want to
-- create. Tag keys are case sensitive. Tag values are case sensitive and
-- can be null.
--
-- 'name', 'createLedger_name' - The name of the ledger that you want to create. The name must be unique
-- among all of the ledgers in your Amazon Web Services account in the
-- current Region.
--
-- Naming constraints for ledger names are defined in
-- <https://docs.aws.amazon.com/qldb/latest/developerguide/limits.html#limits.naming Quotas in Amazon QLDB>
-- in the /Amazon QLDB Developer Guide/.
--
-- 'permissionsMode', 'createLedger_permissionsMode' - The permissions mode to assign to the ledger that you want to create.
-- This parameter can have one of the following values:
--
-- -   @ALLOW_ALL@: A legacy permissions mode that enables access control
--     with API-level granularity for ledgers.
--
--     This mode allows users who have the @SendCommand@ API permission for
--     this ledger to run all PartiQL commands (hence, @ALLOW_ALL@) on any
--     tables in the specified ledger. This mode disregards any table-level
--     or command-level IAM permissions policies that you create for the
--     ledger.
--
-- -   @STANDARD@: (/Recommended/) A permissions mode that enables access
--     control with finer granularity for ledgers, tables, and PartiQL
--     commands.
--
--     By default, this mode denies all user requests to run any PartiQL
--     commands on any tables in this ledger. To allow PartiQL commands to
--     run, you must create IAM permissions policies for specific table
--     resources and PartiQL actions, in addition to the @SendCommand@ API
--     permission for the ledger. For information, see
--     <https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started-standard-mode.html Getting started with the standard permissions mode>
--     in the /Amazon QLDB Developer Guide/.
--
-- We strongly recommend using the @STANDARD@ permissions mode to maximize
-- the security of your ledger data.
newCreateLedger ::
  -- | 'name'
  Prelude.Text ->
  -- | 'permissionsMode'
  PermissionsMode ->
  CreateLedger
newCreateLedger :: Text -> PermissionsMode -> CreateLedger
newCreateLedger Text
pName_ PermissionsMode
pPermissionsMode_ =
  CreateLedger'
    { $sel:deletionProtection:CreateLedger' :: Maybe Bool
deletionProtection = forall a. Maybe a
Prelude.Nothing,
      $sel:kmsKey:CreateLedger' :: Maybe Text
kmsKey = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateLedger' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateLedger' :: Text
name = Text
pName_,
      $sel:permissionsMode:CreateLedger' :: PermissionsMode
permissionsMode = PermissionsMode
pPermissionsMode_
    }

-- | The flag that prevents a ledger from being deleted by any user. If not
-- provided on ledger creation, this feature is enabled (@true@) by
-- default.
--
-- If deletion protection is enabled, you must first disable it before you
-- can delete the ledger. You can disable it by calling the @UpdateLedger@
-- operation to set the flag to @false@.
createLedger_deletionProtection :: Lens.Lens' CreateLedger (Prelude.Maybe Prelude.Bool)
createLedger_deletionProtection :: Lens' CreateLedger (Maybe Bool)
createLedger_deletionProtection = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedger' {Maybe Bool
deletionProtection :: Maybe Bool
$sel:deletionProtection:CreateLedger' :: CreateLedger -> Maybe Bool
deletionProtection} -> Maybe Bool
deletionProtection) (\s :: CreateLedger
s@CreateLedger' {} Maybe Bool
a -> CreateLedger
s {$sel:deletionProtection:CreateLedger' :: Maybe Bool
deletionProtection = Maybe Bool
a} :: CreateLedger)

-- | The key in Key Management Service (KMS) to use for encryption of data at
-- rest in the ledger. For more information, see
-- <https://docs.aws.amazon.com/qldb/latest/developerguide/encryption-at-rest.html Encryption at rest>
-- in the /Amazon QLDB Developer Guide/.
--
-- Use one of the following options to specify this parameter:
--
-- -   @AWS_OWNED_KMS_KEY@: Use an KMS key that is owned and managed by
--     Amazon Web Services on your behalf.
--
-- -   __Undefined__: By default, use an Amazon Web Services owned KMS key.
--
-- -   __A valid symmetric customer managed KMS key__: Use the specified
--     KMS key in your account that you create, own, and manage.
--
--     Amazon QLDB does not support asymmetric keys. For more information,
--     see
--     <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Using symmetric and asymmetric keys>
--     in the /Key Management Service Developer Guide/.
--
-- To specify a customer managed KMS key, you can use its key ID, Amazon
-- Resource Name (ARN), alias name, or alias ARN. When using an alias name,
-- prefix it with @\"alias\/\"@. To specify a key in a different Amazon Web
-- Services account, you must use the key ARN or alias ARN.
--
-- For example:
--
-- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Key ARN:
--     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Alias name: @alias\/ExampleAlias@
--
-- -   Alias ARN: @arn:aws:kms:us-east-2:111122223333:alias\/ExampleAlias@
--
-- For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id Key identifiers (KeyId)>
-- in the /Key Management Service Developer Guide/.
createLedger_kmsKey :: Lens.Lens' CreateLedger (Prelude.Maybe Prelude.Text)
createLedger_kmsKey :: Lens' CreateLedger (Maybe Text)
createLedger_kmsKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedger' {Maybe Text
kmsKey :: Maybe Text
$sel:kmsKey:CreateLedger' :: CreateLedger -> Maybe Text
kmsKey} -> Maybe Text
kmsKey) (\s :: CreateLedger
s@CreateLedger' {} Maybe Text
a -> CreateLedger
s {$sel:kmsKey:CreateLedger' :: Maybe Text
kmsKey = Maybe Text
a} :: CreateLedger)

-- | The key-value pairs to add as tags to the ledger that you want to
-- create. Tag keys are case sensitive. Tag values are case sensitive and
-- can be null.
createLedger_tags :: Lens.Lens' CreateLedger (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createLedger_tags :: Lens' CreateLedger (Maybe (HashMap Text Text))
createLedger_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedger' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateLedger' :: CreateLedger -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateLedger
s@CreateLedger' {} Maybe (HashMap Text Text)
a -> CreateLedger
s {$sel:tags:CreateLedger' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateLedger) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the ledger that you want to create. The name must be unique
-- among all of the ledgers in your Amazon Web Services account in the
-- current Region.
--
-- Naming constraints for ledger names are defined in
-- <https://docs.aws.amazon.com/qldb/latest/developerguide/limits.html#limits.naming Quotas in Amazon QLDB>
-- in the /Amazon QLDB Developer Guide/.
createLedger_name :: Lens.Lens' CreateLedger Prelude.Text
createLedger_name :: Lens' CreateLedger Text
createLedger_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedger' {Text
name :: Text
$sel:name:CreateLedger' :: CreateLedger -> Text
name} -> Text
name) (\s :: CreateLedger
s@CreateLedger' {} Text
a -> CreateLedger
s {$sel:name:CreateLedger' :: Text
name = Text
a} :: CreateLedger)

-- | The permissions mode to assign to the ledger that you want to create.
-- This parameter can have one of the following values:
--
-- -   @ALLOW_ALL@: A legacy permissions mode that enables access control
--     with API-level granularity for ledgers.
--
--     This mode allows users who have the @SendCommand@ API permission for
--     this ledger to run all PartiQL commands (hence, @ALLOW_ALL@) on any
--     tables in the specified ledger. This mode disregards any table-level
--     or command-level IAM permissions policies that you create for the
--     ledger.
--
-- -   @STANDARD@: (/Recommended/) A permissions mode that enables access
--     control with finer granularity for ledgers, tables, and PartiQL
--     commands.
--
--     By default, this mode denies all user requests to run any PartiQL
--     commands on any tables in this ledger. To allow PartiQL commands to
--     run, you must create IAM permissions policies for specific table
--     resources and PartiQL actions, in addition to the @SendCommand@ API
--     permission for the ledger. For information, see
--     <https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started-standard-mode.html Getting started with the standard permissions mode>
--     in the /Amazon QLDB Developer Guide/.
--
-- We strongly recommend using the @STANDARD@ permissions mode to maximize
-- the security of your ledger data.
createLedger_permissionsMode :: Lens.Lens' CreateLedger PermissionsMode
createLedger_permissionsMode :: Lens' CreateLedger PermissionsMode
createLedger_permissionsMode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedger' {PermissionsMode
permissionsMode :: PermissionsMode
$sel:permissionsMode:CreateLedger' :: CreateLedger -> PermissionsMode
permissionsMode} -> PermissionsMode
permissionsMode) (\s :: CreateLedger
s@CreateLedger' {} PermissionsMode
a -> CreateLedger
s {$sel:permissionsMode:CreateLedger' :: PermissionsMode
permissionsMode = PermissionsMode
a} :: CreateLedger)

instance Core.AWSRequest CreateLedger where
  type AWSResponse CreateLedger = CreateLedgerResponse
  request :: (Service -> Service) -> CreateLedger -> Request CreateLedger
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateLedger
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateLedger)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe POSIX
-> Maybe Bool
-> Maybe Text
-> Maybe Text
-> Maybe PermissionsMode
-> Maybe LedgerState
-> Int
-> CreateLedgerResponse
CreateLedgerResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Arn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"CreationDateTime")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"DeletionProtection")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"KmsKeyArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"PermissionsMode")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"State")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateLedger where
  hashWithSalt :: Int -> CreateLedger -> Int
hashWithSalt Int
_salt CreateLedger' {Maybe Bool
Maybe Text
Maybe (HashMap Text Text)
Text
PermissionsMode
permissionsMode :: PermissionsMode
name :: Text
tags :: Maybe (HashMap Text Text)
kmsKey :: Maybe Text
deletionProtection :: Maybe Bool
$sel:permissionsMode:CreateLedger' :: CreateLedger -> PermissionsMode
$sel:name:CreateLedger' :: CreateLedger -> Text
$sel:tags:CreateLedger' :: CreateLedger -> Maybe (HashMap Text Text)
$sel:kmsKey:CreateLedger' :: CreateLedger -> Maybe Text
$sel:deletionProtection:CreateLedger' :: CreateLedger -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
deletionProtection
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PermissionsMode
permissionsMode

instance Prelude.NFData CreateLedger where
  rnf :: CreateLedger -> ()
rnf CreateLedger' {Maybe Bool
Maybe Text
Maybe (HashMap Text Text)
Text
PermissionsMode
permissionsMode :: PermissionsMode
name :: Text
tags :: Maybe (HashMap Text Text)
kmsKey :: Maybe Text
deletionProtection :: Maybe Bool
$sel:permissionsMode:CreateLedger' :: CreateLedger -> PermissionsMode
$sel:name:CreateLedger' :: CreateLedger -> Text
$sel:tags:CreateLedger' :: CreateLedger -> Maybe (HashMap Text Text)
$sel:kmsKey:CreateLedger' :: CreateLedger -> Maybe Text
$sel:deletionProtection:CreateLedger' :: CreateLedger -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
deletionProtection
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PermissionsMode
permissionsMode

instance Data.ToHeaders CreateLedger where
  toHeaders :: CreateLedger -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateLedger where
  toJSON :: CreateLedger -> Value
toJSON CreateLedger' {Maybe Bool
Maybe Text
Maybe (HashMap Text Text)
Text
PermissionsMode
permissionsMode :: PermissionsMode
name :: Text
tags :: Maybe (HashMap Text Text)
kmsKey :: Maybe Text
deletionProtection :: Maybe Bool
$sel:permissionsMode:CreateLedger' :: CreateLedger -> PermissionsMode
$sel:name:CreateLedger' :: CreateLedger -> Text
$sel:tags:CreateLedger' :: CreateLedger -> Maybe (HashMap Text Text)
$sel:kmsKey:CreateLedger' :: CreateLedger -> Maybe Text
$sel:deletionProtection:CreateLedger' :: CreateLedger -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DeletionProtection" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
deletionProtection,
            (Key
"KmsKey" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
kmsKey,
            (Key
"Tags" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"PermissionsMode" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= PermissionsMode
permissionsMode)
          ]
      )

instance Data.ToPath CreateLedger where
  toPath :: CreateLedger -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/ledgers"

instance Data.ToQuery CreateLedger where
  toQuery :: CreateLedger -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateLedgerResponse' smart constructor.
data CreateLedgerResponse = CreateLedgerResponse'
  { -- | The Amazon Resource Name (ARN) for the ledger.
    CreateLedgerResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The date and time, in epoch time format, when the ledger was created.
    -- (Epoch time format is the number of seconds elapsed since 12:00:00 AM
    -- January 1, 1970 UTC.)
    CreateLedgerResponse -> Maybe POSIX
creationDateTime :: Prelude.Maybe Data.POSIX,
    -- | The flag that prevents a ledger from being deleted by any user. If not
    -- provided on ledger creation, this feature is enabled (@true@) by
    -- default.
    --
    -- If deletion protection is enabled, you must first disable it before you
    -- can delete the ledger. You can disable it by calling the @UpdateLedger@
    -- operation to set the flag to @false@.
    CreateLedgerResponse -> Maybe Bool
deletionProtection :: Prelude.Maybe Prelude.Bool,
    -- | The ARN of the customer managed KMS key that the ledger uses for
    -- encryption at rest. If this parameter is undefined, the ledger uses an
    -- Amazon Web Services owned KMS key for encryption.
    CreateLedgerResponse -> Maybe Text
kmsKeyArn :: Prelude.Maybe Prelude.Text,
    -- | The name of the ledger.
    CreateLedgerResponse -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The permissions mode of the ledger that you created.
    CreateLedgerResponse -> Maybe PermissionsMode
permissionsMode :: Prelude.Maybe PermissionsMode,
    -- | The current status of the ledger.
    CreateLedgerResponse -> Maybe LedgerState
state :: Prelude.Maybe LedgerState,
    -- | The response's http status code.
    CreateLedgerResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateLedgerResponse -> CreateLedgerResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateLedgerResponse -> CreateLedgerResponse -> Bool
$c/= :: CreateLedgerResponse -> CreateLedgerResponse -> Bool
== :: CreateLedgerResponse -> CreateLedgerResponse -> Bool
$c== :: CreateLedgerResponse -> CreateLedgerResponse -> Bool
Prelude.Eq, ReadPrec [CreateLedgerResponse]
ReadPrec CreateLedgerResponse
Int -> ReadS CreateLedgerResponse
ReadS [CreateLedgerResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateLedgerResponse]
$creadListPrec :: ReadPrec [CreateLedgerResponse]
readPrec :: ReadPrec CreateLedgerResponse
$creadPrec :: ReadPrec CreateLedgerResponse
readList :: ReadS [CreateLedgerResponse]
$creadList :: ReadS [CreateLedgerResponse]
readsPrec :: Int -> ReadS CreateLedgerResponse
$creadsPrec :: Int -> ReadS CreateLedgerResponse
Prelude.Read, Int -> CreateLedgerResponse -> ShowS
[CreateLedgerResponse] -> ShowS
CreateLedgerResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateLedgerResponse] -> ShowS
$cshowList :: [CreateLedgerResponse] -> ShowS
show :: CreateLedgerResponse -> String
$cshow :: CreateLedgerResponse -> String
showsPrec :: Int -> CreateLedgerResponse -> ShowS
$cshowsPrec :: Int -> CreateLedgerResponse -> ShowS
Prelude.Show, forall x. Rep CreateLedgerResponse x -> CreateLedgerResponse
forall x. CreateLedgerResponse -> Rep CreateLedgerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateLedgerResponse x -> CreateLedgerResponse
$cfrom :: forall x. CreateLedgerResponse -> Rep CreateLedgerResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateLedgerResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'arn', 'createLedgerResponse_arn' - The Amazon Resource Name (ARN) for the ledger.
--
-- 'creationDateTime', 'createLedgerResponse_creationDateTime' - The date and time, in epoch time format, when the ledger was created.
-- (Epoch time format is the number of seconds elapsed since 12:00:00 AM
-- January 1, 1970 UTC.)
--
-- 'deletionProtection', 'createLedgerResponse_deletionProtection' - The flag that prevents a ledger from being deleted by any user. If not
-- provided on ledger creation, this feature is enabled (@true@) by
-- default.
--
-- If deletion protection is enabled, you must first disable it before you
-- can delete the ledger. You can disable it by calling the @UpdateLedger@
-- operation to set the flag to @false@.
--
-- 'kmsKeyArn', 'createLedgerResponse_kmsKeyArn' - The ARN of the customer managed KMS key that the ledger uses for
-- encryption at rest. If this parameter is undefined, the ledger uses an
-- Amazon Web Services owned KMS key for encryption.
--
-- 'name', 'createLedgerResponse_name' - The name of the ledger.
--
-- 'permissionsMode', 'createLedgerResponse_permissionsMode' - The permissions mode of the ledger that you created.
--
-- 'state', 'createLedgerResponse_state' - The current status of the ledger.
--
-- 'httpStatus', 'createLedgerResponse_httpStatus' - The response's http status code.
newCreateLedgerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateLedgerResponse
newCreateLedgerResponse :: Int -> CreateLedgerResponse
newCreateLedgerResponse Int
pHttpStatus_ =
  CreateLedgerResponse'
    { $sel:arn:CreateLedgerResponse' :: Maybe Text
arn = forall a. Maybe a
Prelude.Nothing,
      $sel:creationDateTime:CreateLedgerResponse' :: Maybe POSIX
creationDateTime = forall a. Maybe a
Prelude.Nothing,
      $sel:deletionProtection:CreateLedgerResponse' :: Maybe Bool
deletionProtection = forall a. Maybe a
Prelude.Nothing,
      $sel:kmsKeyArn:CreateLedgerResponse' :: Maybe Text
kmsKeyArn = forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateLedgerResponse' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:permissionsMode:CreateLedgerResponse' :: Maybe PermissionsMode
permissionsMode = forall a. Maybe a
Prelude.Nothing,
      $sel:state:CreateLedgerResponse' :: Maybe LedgerState
state = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateLedgerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) for the ledger.
createLedgerResponse_arn :: Lens.Lens' CreateLedgerResponse (Prelude.Maybe Prelude.Text)
createLedgerResponse_arn :: Lens' CreateLedgerResponse (Maybe Text)
createLedgerResponse_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Maybe Text
a -> CreateLedgerResponse
s {$sel:arn:CreateLedgerResponse' :: Maybe Text
arn = Maybe Text
a} :: CreateLedgerResponse)

-- | The date and time, in epoch time format, when the ledger was created.
-- (Epoch time format is the number of seconds elapsed since 12:00:00 AM
-- January 1, 1970 UTC.)
createLedgerResponse_creationDateTime :: Lens.Lens' CreateLedgerResponse (Prelude.Maybe Prelude.UTCTime)
createLedgerResponse_creationDateTime :: Lens' CreateLedgerResponse (Maybe UTCTime)
createLedgerResponse_creationDateTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Maybe POSIX
creationDateTime :: Maybe POSIX
$sel:creationDateTime:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe POSIX
creationDateTime} -> Maybe POSIX
creationDateTime) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Maybe POSIX
a -> CreateLedgerResponse
s {$sel:creationDateTime:CreateLedgerResponse' :: Maybe POSIX
creationDateTime = Maybe POSIX
a} :: CreateLedgerResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The flag that prevents a ledger from being deleted by any user. If not
-- provided on ledger creation, this feature is enabled (@true@) by
-- default.
--
-- If deletion protection is enabled, you must first disable it before you
-- can delete the ledger. You can disable it by calling the @UpdateLedger@
-- operation to set the flag to @false@.
createLedgerResponse_deletionProtection :: Lens.Lens' CreateLedgerResponse (Prelude.Maybe Prelude.Bool)
createLedgerResponse_deletionProtection :: Lens' CreateLedgerResponse (Maybe Bool)
createLedgerResponse_deletionProtection = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Maybe Bool
deletionProtection :: Maybe Bool
$sel:deletionProtection:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Bool
deletionProtection} -> Maybe Bool
deletionProtection) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Maybe Bool
a -> CreateLedgerResponse
s {$sel:deletionProtection:CreateLedgerResponse' :: Maybe Bool
deletionProtection = Maybe Bool
a} :: CreateLedgerResponse)

-- | The ARN of the customer managed KMS key that the ledger uses for
-- encryption at rest. If this parameter is undefined, the ledger uses an
-- Amazon Web Services owned KMS key for encryption.
createLedgerResponse_kmsKeyArn :: Lens.Lens' CreateLedgerResponse (Prelude.Maybe Prelude.Text)
createLedgerResponse_kmsKeyArn :: Lens' CreateLedgerResponse (Maybe Text)
createLedgerResponse_kmsKeyArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Maybe Text
kmsKeyArn :: Maybe Text
$sel:kmsKeyArn:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Text
kmsKeyArn} -> Maybe Text
kmsKeyArn) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Maybe Text
a -> CreateLedgerResponse
s {$sel:kmsKeyArn:CreateLedgerResponse' :: Maybe Text
kmsKeyArn = Maybe Text
a} :: CreateLedgerResponse)

-- | The name of the ledger.
createLedgerResponse_name :: Lens.Lens' CreateLedgerResponse (Prelude.Maybe Prelude.Text)
createLedgerResponse_name :: Lens' CreateLedgerResponse (Maybe Text)
createLedgerResponse_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Maybe Text
name :: Maybe Text
$sel:name:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Text
name} -> Maybe Text
name) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Maybe Text
a -> CreateLedgerResponse
s {$sel:name:CreateLedgerResponse' :: Maybe Text
name = Maybe Text
a} :: CreateLedgerResponse)

-- | The permissions mode of the ledger that you created.
createLedgerResponse_permissionsMode :: Lens.Lens' CreateLedgerResponse (Prelude.Maybe PermissionsMode)
createLedgerResponse_permissionsMode :: Lens' CreateLedgerResponse (Maybe PermissionsMode)
createLedgerResponse_permissionsMode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Maybe PermissionsMode
permissionsMode :: Maybe PermissionsMode
$sel:permissionsMode:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe PermissionsMode
permissionsMode} -> Maybe PermissionsMode
permissionsMode) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Maybe PermissionsMode
a -> CreateLedgerResponse
s {$sel:permissionsMode:CreateLedgerResponse' :: Maybe PermissionsMode
permissionsMode = Maybe PermissionsMode
a} :: CreateLedgerResponse)

-- | The current status of the ledger.
createLedgerResponse_state :: Lens.Lens' CreateLedgerResponse (Prelude.Maybe LedgerState)
createLedgerResponse_state :: Lens' CreateLedgerResponse (Maybe LedgerState)
createLedgerResponse_state = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Maybe LedgerState
state :: Maybe LedgerState
$sel:state:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe LedgerState
state} -> Maybe LedgerState
state) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Maybe LedgerState
a -> CreateLedgerResponse
s {$sel:state:CreateLedgerResponse' :: Maybe LedgerState
state = Maybe LedgerState
a} :: CreateLedgerResponse)

-- | The response's http status code.
createLedgerResponse_httpStatus :: Lens.Lens' CreateLedgerResponse Prelude.Int
createLedgerResponse_httpStatus :: Lens' CreateLedgerResponse Int
createLedgerResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLedgerResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateLedgerResponse' :: CreateLedgerResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateLedgerResponse
s@CreateLedgerResponse' {} Int
a -> CreateLedgerResponse
s {$sel:httpStatus:CreateLedgerResponse' :: Int
httpStatus = Int
a} :: CreateLedgerResponse)

instance Prelude.NFData CreateLedgerResponse where
  rnf :: CreateLedgerResponse -> ()
rnf CreateLedgerResponse' {Int
Maybe Bool
Maybe Text
Maybe POSIX
Maybe LedgerState
Maybe PermissionsMode
httpStatus :: Int
state :: Maybe LedgerState
permissionsMode :: Maybe PermissionsMode
name :: Maybe Text
kmsKeyArn :: Maybe Text
deletionProtection :: Maybe Bool
creationDateTime :: Maybe POSIX
arn :: Maybe Text
$sel:httpStatus:CreateLedgerResponse' :: CreateLedgerResponse -> Int
$sel:state:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe LedgerState
$sel:permissionsMode:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe PermissionsMode
$sel:name:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Text
$sel:kmsKeyArn:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Text
$sel:deletionProtection:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Bool
$sel:creationDateTime:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe POSIX
$sel:arn:CreateLedgerResponse' :: CreateLedgerResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
creationDateTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
deletionProtection
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PermissionsMode
permissionsMode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe LedgerState
state
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus