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

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

-- |
-- Module      : Amazonka.HealthLake.Types.KmsEncryptionConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.HealthLake.Types.KmsEncryptionConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.HealthLake.Types.CmkType
import qualified Amazonka.Prelude as Prelude

-- | The customer-managed-key(CMK) used when creating a Data Store. If a
-- customer owned key is not specified, an AWS owned key will be used for
-- encryption.
--
-- /See:/ 'newKmsEncryptionConfig' smart constructor.
data KmsEncryptionConfig = KmsEncryptionConfig'
  { -- | The KMS encryption key id\/alias used to encrypt the Data Store contents
    -- at rest.
    KmsEncryptionConfig -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | The type of customer-managed-key(CMK) used for encyrption. The two types
    -- of supported CMKs are customer owned CMKs and AWS owned CMKs.
    KmsEncryptionConfig -> CmkType
cmkType :: CmkType
  }
  deriving (KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
$c/= :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
== :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
$c== :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
Prelude.Eq, ReadPrec [KmsEncryptionConfig]
ReadPrec KmsEncryptionConfig
Int -> ReadS KmsEncryptionConfig
ReadS [KmsEncryptionConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KmsEncryptionConfig]
$creadListPrec :: ReadPrec [KmsEncryptionConfig]
readPrec :: ReadPrec KmsEncryptionConfig
$creadPrec :: ReadPrec KmsEncryptionConfig
readList :: ReadS [KmsEncryptionConfig]
$creadList :: ReadS [KmsEncryptionConfig]
readsPrec :: Int -> ReadS KmsEncryptionConfig
$creadsPrec :: Int -> ReadS KmsEncryptionConfig
Prelude.Read, Int -> KmsEncryptionConfig -> ShowS
[KmsEncryptionConfig] -> ShowS
KmsEncryptionConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KmsEncryptionConfig] -> ShowS
$cshowList :: [KmsEncryptionConfig] -> ShowS
show :: KmsEncryptionConfig -> String
$cshow :: KmsEncryptionConfig -> String
showsPrec :: Int -> KmsEncryptionConfig -> ShowS
$cshowsPrec :: Int -> KmsEncryptionConfig -> ShowS
Prelude.Show, forall x. Rep KmsEncryptionConfig x -> KmsEncryptionConfig
forall x. KmsEncryptionConfig -> Rep KmsEncryptionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KmsEncryptionConfig x -> KmsEncryptionConfig
$cfrom :: forall x. KmsEncryptionConfig -> Rep KmsEncryptionConfig x
Prelude.Generic)

-- |
-- Create a value of 'KmsEncryptionConfig' 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:
--
-- 'kmsKeyId', 'kmsEncryptionConfig_kmsKeyId' - The KMS encryption key id\/alias used to encrypt the Data Store contents
-- at rest.
--
-- 'cmkType', 'kmsEncryptionConfig_cmkType' - The type of customer-managed-key(CMK) used for encyrption. The two types
-- of supported CMKs are customer owned CMKs and AWS owned CMKs.
newKmsEncryptionConfig ::
  -- | 'cmkType'
  CmkType ->
  KmsEncryptionConfig
newKmsEncryptionConfig :: CmkType -> KmsEncryptionConfig
newKmsEncryptionConfig CmkType
pCmkType_ =
  KmsEncryptionConfig'
    { $sel:kmsKeyId:KmsEncryptionConfig' :: Maybe Text
kmsKeyId = forall a. Maybe a
Prelude.Nothing,
      $sel:cmkType:KmsEncryptionConfig' :: CmkType
cmkType = CmkType
pCmkType_
    }

-- | The KMS encryption key id\/alias used to encrypt the Data Store contents
-- at rest.
kmsEncryptionConfig_kmsKeyId :: Lens.Lens' KmsEncryptionConfig (Prelude.Maybe Prelude.Text)
kmsEncryptionConfig_kmsKeyId :: Lens' KmsEncryptionConfig (Maybe Text)
kmsEncryptionConfig_kmsKeyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsEncryptionConfig' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:KmsEncryptionConfig' :: KmsEncryptionConfig -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: KmsEncryptionConfig
s@KmsEncryptionConfig' {} Maybe Text
a -> KmsEncryptionConfig
s {$sel:kmsKeyId:KmsEncryptionConfig' :: Maybe Text
kmsKeyId = Maybe Text
a} :: KmsEncryptionConfig)

-- | The type of customer-managed-key(CMK) used for encyrption. The two types
-- of supported CMKs are customer owned CMKs and AWS owned CMKs.
kmsEncryptionConfig_cmkType :: Lens.Lens' KmsEncryptionConfig CmkType
kmsEncryptionConfig_cmkType :: Lens' KmsEncryptionConfig CmkType
kmsEncryptionConfig_cmkType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsEncryptionConfig' {CmkType
cmkType :: CmkType
$sel:cmkType:KmsEncryptionConfig' :: KmsEncryptionConfig -> CmkType
cmkType} -> CmkType
cmkType) (\s :: KmsEncryptionConfig
s@KmsEncryptionConfig' {} CmkType
a -> KmsEncryptionConfig
s {$sel:cmkType:KmsEncryptionConfig' :: CmkType
cmkType = CmkType
a} :: KmsEncryptionConfig)

instance Data.FromJSON KmsEncryptionConfig where
  parseJSON :: Value -> Parser KmsEncryptionConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KmsEncryptionConfig"
      ( \Object
x ->
          Maybe Text -> CmkType -> KmsEncryptionConfig
KmsEncryptionConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"KmsKeyId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"CmkType")
      )

instance Prelude.Hashable KmsEncryptionConfig where
  hashWithSalt :: Int -> KmsEncryptionConfig -> Int
hashWithSalt Int
_salt KmsEncryptionConfig' {Maybe Text
CmkType
cmkType :: CmkType
kmsKeyId :: Maybe Text
$sel:cmkType:KmsEncryptionConfig' :: KmsEncryptionConfig -> CmkType
$sel:kmsKeyId:KmsEncryptionConfig' :: KmsEncryptionConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CmkType
cmkType

instance Prelude.NFData KmsEncryptionConfig where
  rnf :: KmsEncryptionConfig -> ()
rnf KmsEncryptionConfig' {Maybe Text
CmkType
cmkType :: CmkType
kmsKeyId :: Maybe Text
$sel:cmkType:KmsEncryptionConfig' :: KmsEncryptionConfig -> CmkType
$sel:kmsKeyId:KmsEncryptionConfig' :: KmsEncryptionConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf CmkType
cmkType

instance Data.ToJSON KmsEncryptionConfig where
  toJSON :: KmsEncryptionConfig -> Value
toJSON KmsEncryptionConfig' {Maybe Text
CmkType
cmkType :: CmkType
kmsKeyId :: Maybe Text
$sel:cmkType:KmsEncryptionConfig' :: KmsEncryptionConfig -> CmkType
$sel:kmsKeyId:KmsEncryptionConfig' :: KmsEncryptionConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"KmsKeyId" 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
kmsKeyId,
            forall a. a -> Maybe a
Prelude.Just (Key
"CmkType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= CmkType
cmkType)
          ]
      )