{-# 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.FieldPatterns
-- 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.FieldPatterns where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex data type that includes the field patterns to match for
-- field-level encryption.
--
-- /See:/ 'newFieldPatterns' smart constructor.
data FieldPatterns = FieldPatterns'
  { -- | An array of the field-level encryption field patterns.
    FieldPatterns -> Maybe [Text]
items :: Prelude.Maybe [Prelude.Text],
    -- | The number of field-level encryption field patterns.
    FieldPatterns -> Int
quantity :: Prelude.Int
  }
  deriving (FieldPatterns -> FieldPatterns -> Bool
(FieldPatterns -> FieldPatterns -> Bool)
-> (FieldPatterns -> FieldPatterns -> Bool) -> Eq FieldPatterns
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldPatterns -> FieldPatterns -> Bool
$c/= :: FieldPatterns -> FieldPatterns -> Bool
== :: FieldPatterns -> FieldPatterns -> Bool
$c== :: FieldPatterns -> FieldPatterns -> Bool
Prelude.Eq, ReadPrec [FieldPatterns]
ReadPrec FieldPatterns
Int -> ReadS FieldPatterns
ReadS [FieldPatterns]
(Int -> ReadS FieldPatterns)
-> ReadS [FieldPatterns]
-> ReadPrec FieldPatterns
-> ReadPrec [FieldPatterns]
-> Read FieldPatterns
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FieldPatterns]
$creadListPrec :: ReadPrec [FieldPatterns]
readPrec :: ReadPrec FieldPatterns
$creadPrec :: ReadPrec FieldPatterns
readList :: ReadS [FieldPatterns]
$creadList :: ReadS [FieldPatterns]
readsPrec :: Int -> ReadS FieldPatterns
$creadsPrec :: Int -> ReadS FieldPatterns
Prelude.Read, Int -> FieldPatterns -> ShowS
[FieldPatterns] -> ShowS
FieldPatterns -> String
(Int -> FieldPatterns -> ShowS)
-> (FieldPatterns -> String)
-> ([FieldPatterns] -> ShowS)
-> Show FieldPatterns
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldPatterns] -> ShowS
$cshowList :: [FieldPatterns] -> ShowS
show :: FieldPatterns -> String
$cshow :: FieldPatterns -> String
showsPrec :: Int -> FieldPatterns -> ShowS
$cshowsPrec :: Int -> FieldPatterns -> ShowS
Prelude.Show, (forall x. FieldPatterns -> Rep FieldPatterns x)
-> (forall x. Rep FieldPatterns x -> FieldPatterns)
-> Generic FieldPatterns
forall x. Rep FieldPatterns x -> FieldPatterns
forall x. FieldPatterns -> Rep FieldPatterns x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FieldPatterns x -> FieldPatterns
$cfrom :: forall x. FieldPatterns -> Rep FieldPatterns x
Prelude.Generic)

-- |
-- Create a value of 'FieldPatterns' 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:
--
-- 'items', 'fieldPatterns_items' - An array of the field-level encryption field patterns.
--
-- 'quantity', 'fieldPatterns_quantity' - The number of field-level encryption field patterns.
newFieldPatterns ::
  -- | 'quantity'
  Prelude.Int ->
  FieldPatterns
newFieldPatterns :: Int -> FieldPatterns
newFieldPatterns Int
pQuantity_ =
  FieldPatterns' :: Maybe [Text] -> Int -> FieldPatterns
FieldPatterns'
    { $sel:items:FieldPatterns' :: Maybe [Text]
items = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:FieldPatterns' :: Int
quantity = Int
pQuantity_
    }

-- | An array of the field-level encryption field patterns.
fieldPatterns_items :: Lens.Lens' FieldPatterns (Prelude.Maybe [Prelude.Text])
fieldPatterns_items :: (Maybe [Text] -> f (Maybe [Text]))
-> FieldPatterns -> f FieldPatterns
fieldPatterns_items = (FieldPatterns -> Maybe [Text])
-> (FieldPatterns -> Maybe [Text] -> FieldPatterns)
-> Lens FieldPatterns FieldPatterns (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldPatterns' {Maybe [Text]
items :: Maybe [Text]
$sel:items:FieldPatterns' :: FieldPatterns -> Maybe [Text]
items} -> Maybe [Text]
items) (\s :: FieldPatterns
s@FieldPatterns' {} Maybe [Text]
a -> FieldPatterns
s {$sel:items:FieldPatterns' :: Maybe [Text]
items = Maybe [Text]
a} :: FieldPatterns) ((Maybe [Text] -> f (Maybe [Text]))
 -> FieldPatterns -> f FieldPatterns)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> FieldPatterns
-> f FieldPatterns
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of field-level encryption field patterns.
fieldPatterns_quantity :: Lens.Lens' FieldPatterns Prelude.Int
fieldPatterns_quantity :: (Int -> f Int) -> FieldPatterns -> f FieldPatterns
fieldPatterns_quantity = (FieldPatterns -> Int)
-> (FieldPatterns -> Int -> FieldPatterns)
-> Lens FieldPatterns FieldPatterns Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldPatterns' {Int
quantity :: Int
$sel:quantity:FieldPatterns' :: FieldPatterns -> Int
quantity} -> Int
quantity) (\s :: FieldPatterns
s@FieldPatterns' {} Int
a -> FieldPatterns
s {$sel:quantity:FieldPatterns' :: Int
quantity = Int
a} :: FieldPatterns)

instance Core.FromXML FieldPatterns where
  parseXML :: [Node] -> Either String FieldPatterns
parseXML [Node]
x =
    Maybe [Text] -> Int -> FieldPatterns
FieldPatterns'
      (Maybe [Text] -> Int -> FieldPatterns)
-> Either String (Maybe [Text])
-> Either String (Int -> FieldPatterns)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Items" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Text]))
-> Either String (Maybe [Text])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Text])
-> [Node] -> Either String (Maybe [Text])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"FieldPattern")
                  )
      Either String (Int -> FieldPatterns)
-> Either String Int -> Either String FieldPatterns
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Int
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Quantity")

instance Prelude.Hashable FieldPatterns

instance Prelude.NFData FieldPatterns

instance Core.ToXML FieldPatterns where
  toXML :: FieldPatterns -> XML
toXML FieldPatterns' {Int
Maybe [Text]
quantity :: Int
items :: Maybe [Text]
$sel:quantity:FieldPatterns' :: FieldPatterns -> Int
$sel:items:FieldPatterns' :: FieldPatterns -> Maybe [Text]
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe XML -> XML
forall a. ToXML a => a -> XML
Core.toXML
            (Name -> [Text] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"FieldPattern" ([Text] -> XML) -> Maybe [Text] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
items),
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity
      ]