{-# 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.CloudFront.Types.ContentTypeProfileConfig
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudFront.Types.ContentTypeProfileConfig where

import Amazonka.CloudFront.Types.ContentTypeProfiles
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The configuration for a field-level encryption content type-profile
-- mapping.
--
-- /See:/ 'newContentTypeProfileConfig' smart constructor.
data ContentTypeProfileConfig = ContentTypeProfileConfig'
  { -- | The configuration for a field-level encryption content type-profile.
    ContentTypeProfileConfig -> Maybe ContentTypeProfiles
contentTypeProfiles :: Prelude.Maybe ContentTypeProfiles,
    -- | The setting in a field-level encryption content type-profile mapping
    -- that specifies what to do when an unknown content type is provided for
    -- the profile. If true, content is forwarded without being encrypted when
    -- the content type is unknown. If false (the default), an error is
    -- returned when the content type is unknown.
    ContentTypeProfileConfig -> Bool
forwardWhenContentTypeIsUnknown :: Prelude.Bool
  }
  deriving (ContentTypeProfileConfig -> ContentTypeProfileConfig -> Bool
(ContentTypeProfileConfig -> ContentTypeProfileConfig -> Bool)
-> (ContentTypeProfileConfig -> ContentTypeProfileConfig -> Bool)
-> Eq ContentTypeProfileConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ContentTypeProfileConfig -> ContentTypeProfileConfig -> Bool
$c/= :: ContentTypeProfileConfig -> ContentTypeProfileConfig -> Bool
== :: ContentTypeProfileConfig -> ContentTypeProfileConfig -> Bool
$c== :: ContentTypeProfileConfig -> ContentTypeProfileConfig -> Bool
Prelude.Eq, ReadPrec [ContentTypeProfileConfig]
ReadPrec ContentTypeProfileConfig
Int -> ReadS ContentTypeProfileConfig
ReadS [ContentTypeProfileConfig]
(Int -> ReadS ContentTypeProfileConfig)
-> ReadS [ContentTypeProfileConfig]
-> ReadPrec ContentTypeProfileConfig
-> ReadPrec [ContentTypeProfileConfig]
-> Read ContentTypeProfileConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ContentTypeProfileConfig]
$creadListPrec :: ReadPrec [ContentTypeProfileConfig]
readPrec :: ReadPrec ContentTypeProfileConfig
$creadPrec :: ReadPrec ContentTypeProfileConfig
readList :: ReadS [ContentTypeProfileConfig]
$creadList :: ReadS [ContentTypeProfileConfig]
readsPrec :: Int -> ReadS ContentTypeProfileConfig
$creadsPrec :: Int -> ReadS ContentTypeProfileConfig
Prelude.Read, Int -> ContentTypeProfileConfig -> ShowS
[ContentTypeProfileConfig] -> ShowS
ContentTypeProfileConfig -> String
(Int -> ContentTypeProfileConfig -> ShowS)
-> (ContentTypeProfileConfig -> String)
-> ([ContentTypeProfileConfig] -> ShowS)
-> Show ContentTypeProfileConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ContentTypeProfileConfig] -> ShowS
$cshowList :: [ContentTypeProfileConfig] -> ShowS
show :: ContentTypeProfileConfig -> String
$cshow :: ContentTypeProfileConfig -> String
showsPrec :: Int -> ContentTypeProfileConfig -> ShowS
$cshowsPrec :: Int -> ContentTypeProfileConfig -> ShowS
Prelude.Show, (forall x.
 ContentTypeProfileConfig -> Rep ContentTypeProfileConfig x)
-> (forall x.
    Rep ContentTypeProfileConfig x -> ContentTypeProfileConfig)
-> Generic ContentTypeProfileConfig
forall x.
Rep ContentTypeProfileConfig x -> ContentTypeProfileConfig
forall x.
ContentTypeProfileConfig -> Rep ContentTypeProfileConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ContentTypeProfileConfig x -> ContentTypeProfileConfig
$cfrom :: forall x.
ContentTypeProfileConfig -> Rep ContentTypeProfileConfig x
Prelude.Generic)

-- |
-- Create a value of 'ContentTypeProfileConfig' 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:
--
-- 'contentTypeProfiles', 'contentTypeProfileConfig_contentTypeProfiles' - The configuration for a field-level encryption content type-profile.
--
-- 'forwardWhenContentTypeIsUnknown', 'contentTypeProfileConfig_forwardWhenContentTypeIsUnknown' - The setting in a field-level encryption content type-profile mapping
-- that specifies what to do when an unknown content type is provided for
-- the profile. If true, content is forwarded without being encrypted when
-- the content type is unknown. If false (the default), an error is
-- returned when the content type is unknown.
newContentTypeProfileConfig ::
  -- | 'forwardWhenContentTypeIsUnknown'
  Prelude.Bool ->
  ContentTypeProfileConfig
newContentTypeProfileConfig :: Bool -> ContentTypeProfileConfig
newContentTypeProfileConfig
  Bool
pForwardWhenContentTypeIsUnknown_ =
    ContentTypeProfileConfig' :: Maybe ContentTypeProfiles -> Bool -> ContentTypeProfileConfig
ContentTypeProfileConfig'
      { $sel:contentTypeProfiles:ContentTypeProfileConfig' :: Maybe ContentTypeProfiles
contentTypeProfiles =
          Maybe ContentTypeProfiles
forall a. Maybe a
Prelude.Nothing,
        $sel:forwardWhenContentTypeIsUnknown:ContentTypeProfileConfig' :: Bool
forwardWhenContentTypeIsUnknown =
          Bool
pForwardWhenContentTypeIsUnknown_
      }

-- | The configuration for a field-level encryption content type-profile.
contentTypeProfileConfig_contentTypeProfiles :: Lens.Lens' ContentTypeProfileConfig (Prelude.Maybe ContentTypeProfiles)
contentTypeProfileConfig_contentTypeProfiles :: (Maybe ContentTypeProfiles -> f (Maybe ContentTypeProfiles))
-> ContentTypeProfileConfig -> f ContentTypeProfileConfig
contentTypeProfileConfig_contentTypeProfiles = (ContentTypeProfileConfig -> Maybe ContentTypeProfiles)
-> (ContentTypeProfileConfig
    -> Maybe ContentTypeProfiles -> ContentTypeProfileConfig)
-> Lens
     ContentTypeProfileConfig
     ContentTypeProfileConfig
     (Maybe ContentTypeProfiles)
     (Maybe ContentTypeProfiles)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContentTypeProfileConfig' {Maybe ContentTypeProfiles
contentTypeProfiles :: Maybe ContentTypeProfiles
$sel:contentTypeProfiles:ContentTypeProfileConfig' :: ContentTypeProfileConfig -> Maybe ContentTypeProfiles
contentTypeProfiles} -> Maybe ContentTypeProfiles
contentTypeProfiles) (\s :: ContentTypeProfileConfig
s@ContentTypeProfileConfig' {} Maybe ContentTypeProfiles
a -> ContentTypeProfileConfig
s {$sel:contentTypeProfiles:ContentTypeProfileConfig' :: Maybe ContentTypeProfiles
contentTypeProfiles = Maybe ContentTypeProfiles
a} :: ContentTypeProfileConfig)

-- | The setting in a field-level encryption content type-profile mapping
-- that specifies what to do when an unknown content type is provided for
-- the profile. If true, content is forwarded without being encrypted when
-- the content type is unknown. If false (the default), an error is
-- returned when the content type is unknown.
contentTypeProfileConfig_forwardWhenContentTypeIsUnknown :: Lens.Lens' ContentTypeProfileConfig Prelude.Bool
contentTypeProfileConfig_forwardWhenContentTypeIsUnknown :: (Bool -> f Bool)
-> ContentTypeProfileConfig -> f ContentTypeProfileConfig
contentTypeProfileConfig_forwardWhenContentTypeIsUnknown = (ContentTypeProfileConfig -> Bool)
-> (ContentTypeProfileConfig -> Bool -> ContentTypeProfileConfig)
-> Lens ContentTypeProfileConfig ContentTypeProfileConfig Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContentTypeProfileConfig' {Bool
forwardWhenContentTypeIsUnknown :: Bool
$sel:forwardWhenContentTypeIsUnknown:ContentTypeProfileConfig' :: ContentTypeProfileConfig -> Bool
forwardWhenContentTypeIsUnknown} -> Bool
forwardWhenContentTypeIsUnknown) (\s :: ContentTypeProfileConfig
s@ContentTypeProfileConfig' {} Bool
a -> ContentTypeProfileConfig
s {$sel:forwardWhenContentTypeIsUnknown:ContentTypeProfileConfig' :: Bool
forwardWhenContentTypeIsUnknown = Bool
a} :: ContentTypeProfileConfig)

instance Core.FromXML ContentTypeProfileConfig where
  parseXML :: [Node] -> Either String ContentTypeProfileConfig
parseXML [Node]
x =
    Maybe ContentTypeProfiles -> Bool -> ContentTypeProfileConfig
ContentTypeProfileConfig'
      (Maybe ContentTypeProfiles -> Bool -> ContentTypeProfileConfig)
-> Either String (Maybe ContentTypeProfiles)
-> Either String (Bool -> ContentTypeProfileConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe ContentTypeProfiles)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ContentTypeProfiles")
      Either String (Bool -> ContentTypeProfileConfig)
-> Either String Bool -> Either String ContentTypeProfileConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Bool
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ForwardWhenContentTypeIsUnknown")

instance Prelude.Hashable ContentTypeProfileConfig

instance Prelude.NFData ContentTypeProfileConfig

instance Core.ToXML ContentTypeProfileConfig where
  toXML :: ContentTypeProfileConfig -> XML
toXML ContentTypeProfileConfig' {Bool
Maybe ContentTypeProfiles
forwardWhenContentTypeIsUnknown :: Bool
contentTypeProfiles :: Maybe ContentTypeProfiles
$sel:forwardWhenContentTypeIsUnknown:ContentTypeProfileConfig' :: ContentTypeProfileConfig -> Bool
$sel:contentTypeProfiles:ContentTypeProfileConfig' :: ContentTypeProfileConfig -> Maybe ContentTypeProfiles
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"ContentTypeProfiles" Name -> Maybe ContentTypeProfiles -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe ContentTypeProfiles
contentTypeProfiles,
        Name
"ForwardWhenContentTypeIsUnknown"
          Name -> Bool -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Bool
forwardWhenContentTypeIsUnknown
      ]