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

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

-- | A complex type that controls:
--
-- -   Whether CloudFront replaces HTTP status codes in the 4xx and 5xx
--     range with custom error messages before returning the response to
--     the viewer.
--
-- -   How long CloudFront caches HTTP status codes in the 4xx and 5xx
--     range.
--
-- For more information about custom error pages, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html Customizing Error Responses>
-- in the /Amazon CloudFront Developer Guide/.
--
-- /See:/ 'newCustomErrorResponses' smart constructor.
data CustomErrorResponses = CustomErrorResponses'
  { -- | A complex type that contains a @CustomErrorResponse@ element for each
    -- HTTP status code for which you want to specify a custom error page
    -- and\/or a caching duration.
    CustomErrorResponses -> Maybe [CustomErrorResponse]
items :: Prelude.Maybe [CustomErrorResponse],
    -- | The number of HTTP status codes for which you want to specify a custom
    -- error page and\/or a caching duration. If @Quantity@ is @0@, you can
    -- omit @Items@.
    CustomErrorResponses -> Int
quantity :: Prelude.Int
  }
  deriving (CustomErrorResponses -> CustomErrorResponses -> Bool
(CustomErrorResponses -> CustomErrorResponses -> Bool)
-> (CustomErrorResponses -> CustomErrorResponses -> Bool)
-> Eq CustomErrorResponses
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomErrorResponses -> CustomErrorResponses -> Bool
$c/= :: CustomErrorResponses -> CustomErrorResponses -> Bool
== :: CustomErrorResponses -> CustomErrorResponses -> Bool
$c== :: CustomErrorResponses -> CustomErrorResponses -> Bool
Prelude.Eq, ReadPrec [CustomErrorResponses]
ReadPrec CustomErrorResponses
Int -> ReadS CustomErrorResponses
ReadS [CustomErrorResponses]
(Int -> ReadS CustomErrorResponses)
-> ReadS [CustomErrorResponses]
-> ReadPrec CustomErrorResponses
-> ReadPrec [CustomErrorResponses]
-> Read CustomErrorResponses
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomErrorResponses]
$creadListPrec :: ReadPrec [CustomErrorResponses]
readPrec :: ReadPrec CustomErrorResponses
$creadPrec :: ReadPrec CustomErrorResponses
readList :: ReadS [CustomErrorResponses]
$creadList :: ReadS [CustomErrorResponses]
readsPrec :: Int -> ReadS CustomErrorResponses
$creadsPrec :: Int -> ReadS CustomErrorResponses
Prelude.Read, Int -> CustomErrorResponses -> ShowS
[CustomErrorResponses] -> ShowS
CustomErrorResponses -> String
(Int -> CustomErrorResponses -> ShowS)
-> (CustomErrorResponses -> String)
-> ([CustomErrorResponses] -> ShowS)
-> Show CustomErrorResponses
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomErrorResponses] -> ShowS
$cshowList :: [CustomErrorResponses] -> ShowS
show :: CustomErrorResponses -> String
$cshow :: CustomErrorResponses -> String
showsPrec :: Int -> CustomErrorResponses -> ShowS
$cshowsPrec :: Int -> CustomErrorResponses -> ShowS
Prelude.Show, (forall x. CustomErrorResponses -> Rep CustomErrorResponses x)
-> (forall x. Rep CustomErrorResponses x -> CustomErrorResponses)
-> Generic CustomErrorResponses
forall x. Rep CustomErrorResponses x -> CustomErrorResponses
forall x. CustomErrorResponses -> Rep CustomErrorResponses x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomErrorResponses x -> CustomErrorResponses
$cfrom :: forall x. CustomErrorResponses -> Rep CustomErrorResponses x
Prelude.Generic)

-- |
-- Create a value of 'CustomErrorResponses' 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', 'customErrorResponses_items' - A complex type that contains a @CustomErrorResponse@ element for each
-- HTTP status code for which you want to specify a custom error page
-- and\/or a caching duration.
--
-- 'quantity', 'customErrorResponses_quantity' - The number of HTTP status codes for which you want to specify a custom
-- error page and\/or a caching duration. If @Quantity@ is @0@, you can
-- omit @Items@.
newCustomErrorResponses ::
  -- | 'quantity'
  Prelude.Int ->
  CustomErrorResponses
newCustomErrorResponses :: Int -> CustomErrorResponses
newCustomErrorResponses Int
pQuantity_ =
  CustomErrorResponses' :: Maybe [CustomErrorResponse] -> Int -> CustomErrorResponses
CustomErrorResponses'
    { $sel:items:CustomErrorResponses' :: Maybe [CustomErrorResponse]
items = Maybe [CustomErrorResponse]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:CustomErrorResponses' :: Int
quantity = Int
pQuantity_
    }

-- | A complex type that contains a @CustomErrorResponse@ element for each
-- HTTP status code for which you want to specify a custom error page
-- and\/or a caching duration.
customErrorResponses_items :: Lens.Lens' CustomErrorResponses (Prelude.Maybe [CustomErrorResponse])
customErrorResponses_items :: (Maybe [CustomErrorResponse] -> f (Maybe [CustomErrorResponse]))
-> CustomErrorResponses -> f CustomErrorResponses
customErrorResponses_items = (CustomErrorResponses -> Maybe [CustomErrorResponse])
-> (CustomErrorResponses
    -> Maybe [CustomErrorResponse] -> CustomErrorResponses)
-> Lens
     CustomErrorResponses
     CustomErrorResponses
     (Maybe [CustomErrorResponse])
     (Maybe [CustomErrorResponse])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomErrorResponses' {Maybe [CustomErrorResponse]
items :: Maybe [CustomErrorResponse]
$sel:items:CustomErrorResponses' :: CustomErrorResponses -> Maybe [CustomErrorResponse]
items} -> Maybe [CustomErrorResponse]
items) (\s :: CustomErrorResponses
s@CustomErrorResponses' {} Maybe [CustomErrorResponse]
a -> CustomErrorResponses
s {$sel:items:CustomErrorResponses' :: Maybe [CustomErrorResponse]
items = Maybe [CustomErrorResponse]
a} :: CustomErrorResponses) ((Maybe [CustomErrorResponse] -> f (Maybe [CustomErrorResponse]))
 -> CustomErrorResponses -> f CustomErrorResponses)
-> ((Maybe [CustomErrorResponse]
     -> f (Maybe [CustomErrorResponse]))
    -> Maybe [CustomErrorResponse] -> f (Maybe [CustomErrorResponse]))
-> (Maybe [CustomErrorResponse] -> f (Maybe [CustomErrorResponse]))
-> CustomErrorResponses
-> f CustomErrorResponses
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [CustomErrorResponse]
  [CustomErrorResponse]
  [CustomErrorResponse]
  [CustomErrorResponse]
-> Iso
     (Maybe [CustomErrorResponse])
     (Maybe [CustomErrorResponse])
     (Maybe [CustomErrorResponse])
     (Maybe [CustomErrorResponse])
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
  [CustomErrorResponse]
  [CustomErrorResponse]
  [CustomErrorResponse]
  [CustomErrorResponse]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of HTTP status codes for which you want to specify a custom
-- error page and\/or a caching duration. If @Quantity@ is @0@, you can
-- omit @Items@.
customErrorResponses_quantity :: Lens.Lens' CustomErrorResponses Prelude.Int
customErrorResponses_quantity :: (Int -> f Int) -> CustomErrorResponses -> f CustomErrorResponses
customErrorResponses_quantity = (CustomErrorResponses -> Int)
-> (CustomErrorResponses -> Int -> CustomErrorResponses)
-> Lens CustomErrorResponses CustomErrorResponses Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomErrorResponses' {Int
quantity :: Int
$sel:quantity:CustomErrorResponses' :: CustomErrorResponses -> Int
quantity} -> Int
quantity) (\s :: CustomErrorResponses
s@CustomErrorResponses' {} Int
a -> CustomErrorResponses
s {$sel:quantity:CustomErrorResponses' :: Int
quantity = Int
a} :: CustomErrorResponses)

instance Core.FromXML CustomErrorResponses where
  parseXML :: [Node] -> Either String CustomErrorResponses
parseXML [Node]
x =
    Maybe [CustomErrorResponse] -> Int -> CustomErrorResponses
CustomErrorResponses'
      (Maybe [CustomErrorResponse] -> Int -> CustomErrorResponses)
-> Either String (Maybe [CustomErrorResponse])
-> Either String (Int -> CustomErrorResponses)
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 [CustomErrorResponse]))
-> Either String (Maybe [CustomErrorResponse])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [CustomErrorResponse])
-> [Node] -> Either String (Maybe [CustomErrorResponse])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [CustomErrorResponse]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"CustomErrorResponse")
                  )
      Either String (Int -> CustomErrorResponses)
-> Either String Int -> Either String CustomErrorResponses
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 CustomErrorResponses

instance Prelude.NFData CustomErrorResponses

instance Core.ToXML CustomErrorResponses where
  toXML :: CustomErrorResponses -> XML
toXML CustomErrorResponses' {Int
Maybe [CustomErrorResponse]
quantity :: Int
items :: Maybe [CustomErrorResponse]
$sel:quantity:CustomErrorResponses' :: CustomErrorResponses -> Int
$sel:items:CustomErrorResponses' :: CustomErrorResponses -> Maybe [CustomErrorResponse]
..} =
    [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 -> [CustomErrorResponse] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"CustomErrorResponse"
                ([CustomErrorResponse] -> XML)
-> Maybe [CustomErrorResponse] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [CustomErrorResponse]
items
            ),
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity
      ]