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

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

-- | An invalidation batch.
--
-- /See:/ 'newInvalidationBatch' smart constructor.
data InvalidationBatch = InvalidationBatch'
  { -- | A complex type that contains information about the objects that you want
    -- to invalidate. For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#invalidation-specifying-objects Specifying the Objects to Invalidate>
    -- in the /Amazon CloudFront Developer Guide/.
    InvalidationBatch -> Paths
paths :: Paths,
    -- | A value that you specify to uniquely identify an invalidation request.
    -- CloudFront uses the value to prevent you from accidentally resubmitting
    -- an identical request. Whenever you create a new invalidation request,
    -- you must specify a new value for @CallerReference@ and change other
    -- values in the request as applicable. One way to ensure that the value of
    -- @CallerReference@ is unique is to use a @timestamp@, for example,
    -- @20120301090000@.
    --
    -- If you make a second invalidation request with the same value for
    -- @CallerReference@, and if the rest of the request is the same,
    -- CloudFront doesn\'t create a new invalidation request. Instead,
    -- CloudFront returns information about the invalidation request that you
    -- previously created with the same @CallerReference@.
    --
    -- If @CallerReference@ is a value you already sent in a previous
    -- invalidation batch request but the content of any @Path@ is different
    -- from the original request, CloudFront returns an
    -- @InvalidationBatchAlreadyExists@ error.
    InvalidationBatch -> Text
callerReference :: Prelude.Text
  }
  deriving (InvalidationBatch -> InvalidationBatch -> Bool
(InvalidationBatch -> InvalidationBatch -> Bool)
-> (InvalidationBatch -> InvalidationBatch -> Bool)
-> Eq InvalidationBatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InvalidationBatch -> InvalidationBatch -> Bool
$c/= :: InvalidationBatch -> InvalidationBatch -> Bool
== :: InvalidationBatch -> InvalidationBatch -> Bool
$c== :: InvalidationBatch -> InvalidationBatch -> Bool
Prelude.Eq, ReadPrec [InvalidationBatch]
ReadPrec InvalidationBatch
Int -> ReadS InvalidationBatch
ReadS [InvalidationBatch]
(Int -> ReadS InvalidationBatch)
-> ReadS [InvalidationBatch]
-> ReadPrec InvalidationBatch
-> ReadPrec [InvalidationBatch]
-> Read InvalidationBatch
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InvalidationBatch]
$creadListPrec :: ReadPrec [InvalidationBatch]
readPrec :: ReadPrec InvalidationBatch
$creadPrec :: ReadPrec InvalidationBatch
readList :: ReadS [InvalidationBatch]
$creadList :: ReadS [InvalidationBatch]
readsPrec :: Int -> ReadS InvalidationBatch
$creadsPrec :: Int -> ReadS InvalidationBatch
Prelude.Read, Int -> InvalidationBatch -> ShowS
[InvalidationBatch] -> ShowS
InvalidationBatch -> String
(Int -> InvalidationBatch -> ShowS)
-> (InvalidationBatch -> String)
-> ([InvalidationBatch] -> ShowS)
-> Show InvalidationBatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InvalidationBatch] -> ShowS
$cshowList :: [InvalidationBatch] -> ShowS
show :: InvalidationBatch -> String
$cshow :: InvalidationBatch -> String
showsPrec :: Int -> InvalidationBatch -> ShowS
$cshowsPrec :: Int -> InvalidationBatch -> ShowS
Prelude.Show, (forall x. InvalidationBatch -> Rep InvalidationBatch x)
-> (forall x. Rep InvalidationBatch x -> InvalidationBatch)
-> Generic InvalidationBatch
forall x. Rep InvalidationBatch x -> InvalidationBatch
forall x. InvalidationBatch -> Rep InvalidationBatch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InvalidationBatch x -> InvalidationBatch
$cfrom :: forall x. InvalidationBatch -> Rep InvalidationBatch x
Prelude.Generic)

-- |
-- Create a value of 'InvalidationBatch' 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:
--
-- 'paths', 'invalidationBatch_paths' - A complex type that contains information about the objects that you want
-- to invalidate. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#invalidation-specifying-objects Specifying the Objects to Invalidate>
-- in the /Amazon CloudFront Developer Guide/.
--
-- 'callerReference', 'invalidationBatch_callerReference' - A value that you specify to uniquely identify an invalidation request.
-- CloudFront uses the value to prevent you from accidentally resubmitting
-- an identical request. Whenever you create a new invalidation request,
-- you must specify a new value for @CallerReference@ and change other
-- values in the request as applicable. One way to ensure that the value of
-- @CallerReference@ is unique is to use a @timestamp@, for example,
-- @20120301090000@.
--
-- If you make a second invalidation request with the same value for
-- @CallerReference@, and if the rest of the request is the same,
-- CloudFront doesn\'t create a new invalidation request. Instead,
-- CloudFront returns information about the invalidation request that you
-- previously created with the same @CallerReference@.
--
-- If @CallerReference@ is a value you already sent in a previous
-- invalidation batch request but the content of any @Path@ is different
-- from the original request, CloudFront returns an
-- @InvalidationBatchAlreadyExists@ error.
newInvalidationBatch ::
  -- | 'paths'
  Paths ->
  -- | 'callerReference'
  Prelude.Text ->
  InvalidationBatch
newInvalidationBatch :: Paths -> Text -> InvalidationBatch
newInvalidationBatch Paths
pPaths_ Text
pCallerReference_ =
  InvalidationBatch' :: Paths -> Text -> InvalidationBatch
InvalidationBatch'
    { $sel:paths:InvalidationBatch' :: Paths
paths = Paths
pPaths_,
      $sel:callerReference:InvalidationBatch' :: Text
callerReference = Text
pCallerReference_
    }

-- | A complex type that contains information about the objects that you want
-- to invalidate. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#invalidation-specifying-objects Specifying the Objects to Invalidate>
-- in the /Amazon CloudFront Developer Guide/.
invalidationBatch_paths :: Lens.Lens' InvalidationBatch Paths
invalidationBatch_paths :: (Paths -> f Paths) -> InvalidationBatch -> f InvalidationBatch
invalidationBatch_paths = (InvalidationBatch -> Paths)
-> (InvalidationBatch -> Paths -> InvalidationBatch)
-> Lens InvalidationBatch InvalidationBatch Paths Paths
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InvalidationBatch' {Paths
paths :: Paths
$sel:paths:InvalidationBatch' :: InvalidationBatch -> Paths
paths} -> Paths
paths) (\s :: InvalidationBatch
s@InvalidationBatch' {} Paths
a -> InvalidationBatch
s {$sel:paths:InvalidationBatch' :: Paths
paths = Paths
a} :: InvalidationBatch)

-- | A value that you specify to uniquely identify an invalidation request.
-- CloudFront uses the value to prevent you from accidentally resubmitting
-- an identical request. Whenever you create a new invalidation request,
-- you must specify a new value for @CallerReference@ and change other
-- values in the request as applicable. One way to ensure that the value of
-- @CallerReference@ is unique is to use a @timestamp@, for example,
-- @20120301090000@.
--
-- If you make a second invalidation request with the same value for
-- @CallerReference@, and if the rest of the request is the same,
-- CloudFront doesn\'t create a new invalidation request. Instead,
-- CloudFront returns information about the invalidation request that you
-- previously created with the same @CallerReference@.
--
-- If @CallerReference@ is a value you already sent in a previous
-- invalidation batch request but the content of any @Path@ is different
-- from the original request, CloudFront returns an
-- @InvalidationBatchAlreadyExists@ error.
invalidationBatch_callerReference :: Lens.Lens' InvalidationBatch Prelude.Text
invalidationBatch_callerReference :: (Text -> f Text) -> InvalidationBatch -> f InvalidationBatch
invalidationBatch_callerReference = (InvalidationBatch -> Text)
-> (InvalidationBatch -> Text -> InvalidationBatch)
-> Lens InvalidationBatch InvalidationBatch Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InvalidationBatch' {Text
callerReference :: Text
$sel:callerReference:InvalidationBatch' :: InvalidationBatch -> Text
callerReference} -> Text
callerReference) (\s :: InvalidationBatch
s@InvalidationBatch' {} Text
a -> InvalidationBatch
s {$sel:callerReference:InvalidationBatch' :: Text
callerReference = Text
a} :: InvalidationBatch)

instance Core.FromXML InvalidationBatch where
  parseXML :: [Node] -> Either String InvalidationBatch
parseXML [Node]
x =
    Paths -> Text -> InvalidationBatch
InvalidationBatch'
      (Paths -> Text -> InvalidationBatch)
-> Either String Paths -> Either String (Text -> InvalidationBatch)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Paths
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Paths")
      Either String (Text -> InvalidationBatch)
-> Either String Text -> Either String InvalidationBatch
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"CallerReference")

instance Prelude.Hashable InvalidationBatch

instance Prelude.NFData InvalidationBatch

instance Core.ToXML InvalidationBatch where
  toXML :: InvalidationBatch -> XML
toXML InvalidationBatch' {Text
Paths
callerReference :: Text
paths :: Paths
$sel:callerReference:InvalidationBatch' :: InvalidationBatch -> Text
$sel:paths:InvalidationBatch' :: InvalidationBatch -> Paths
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Paths" Name -> Paths -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Paths
paths,
        Name
"CallerReference" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
callerReference
      ]