{-# 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.Glacier.Types.DataRetrievalPolicy
-- 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.Glacier.Types.DataRetrievalPolicy where

import qualified Amazonka.Core as Core
import Amazonka.Glacier.Types.DataRetrievalRule
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Data retrieval policy.
--
-- /See:/ 'newDataRetrievalPolicy' smart constructor.
data DataRetrievalPolicy = DataRetrievalPolicy'
  { -- | The policy rule. Although this is a list type, currently there must be
    -- only one rule, which contains a Strategy field and optionally a
    -- BytesPerHour field.
    DataRetrievalPolicy -> Maybe [DataRetrievalRule]
rules :: Prelude.Maybe [DataRetrievalRule]
  }
  deriving (DataRetrievalPolicy -> DataRetrievalPolicy -> Bool
(DataRetrievalPolicy -> DataRetrievalPolicy -> Bool)
-> (DataRetrievalPolicy -> DataRetrievalPolicy -> Bool)
-> Eq DataRetrievalPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataRetrievalPolicy -> DataRetrievalPolicy -> Bool
$c/= :: DataRetrievalPolicy -> DataRetrievalPolicy -> Bool
== :: DataRetrievalPolicy -> DataRetrievalPolicy -> Bool
$c== :: DataRetrievalPolicy -> DataRetrievalPolicy -> Bool
Prelude.Eq, ReadPrec [DataRetrievalPolicy]
ReadPrec DataRetrievalPolicy
Int -> ReadS DataRetrievalPolicy
ReadS [DataRetrievalPolicy]
(Int -> ReadS DataRetrievalPolicy)
-> ReadS [DataRetrievalPolicy]
-> ReadPrec DataRetrievalPolicy
-> ReadPrec [DataRetrievalPolicy]
-> Read DataRetrievalPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DataRetrievalPolicy]
$creadListPrec :: ReadPrec [DataRetrievalPolicy]
readPrec :: ReadPrec DataRetrievalPolicy
$creadPrec :: ReadPrec DataRetrievalPolicy
readList :: ReadS [DataRetrievalPolicy]
$creadList :: ReadS [DataRetrievalPolicy]
readsPrec :: Int -> ReadS DataRetrievalPolicy
$creadsPrec :: Int -> ReadS DataRetrievalPolicy
Prelude.Read, Int -> DataRetrievalPolicy -> ShowS
[DataRetrievalPolicy] -> ShowS
DataRetrievalPolicy -> String
(Int -> DataRetrievalPolicy -> ShowS)
-> (DataRetrievalPolicy -> String)
-> ([DataRetrievalPolicy] -> ShowS)
-> Show DataRetrievalPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataRetrievalPolicy] -> ShowS
$cshowList :: [DataRetrievalPolicy] -> ShowS
show :: DataRetrievalPolicy -> String
$cshow :: DataRetrievalPolicy -> String
showsPrec :: Int -> DataRetrievalPolicy -> ShowS
$cshowsPrec :: Int -> DataRetrievalPolicy -> ShowS
Prelude.Show, (forall x. DataRetrievalPolicy -> Rep DataRetrievalPolicy x)
-> (forall x. Rep DataRetrievalPolicy x -> DataRetrievalPolicy)
-> Generic DataRetrievalPolicy
forall x. Rep DataRetrievalPolicy x -> DataRetrievalPolicy
forall x. DataRetrievalPolicy -> Rep DataRetrievalPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DataRetrievalPolicy x -> DataRetrievalPolicy
$cfrom :: forall x. DataRetrievalPolicy -> Rep DataRetrievalPolicy x
Prelude.Generic)

-- |
-- Create a value of 'DataRetrievalPolicy' 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:
--
-- 'rules', 'dataRetrievalPolicy_rules' - The policy rule. Although this is a list type, currently there must be
-- only one rule, which contains a Strategy field and optionally a
-- BytesPerHour field.
newDataRetrievalPolicy ::
  DataRetrievalPolicy
newDataRetrievalPolicy :: DataRetrievalPolicy
newDataRetrievalPolicy =
  DataRetrievalPolicy' :: Maybe [DataRetrievalRule] -> DataRetrievalPolicy
DataRetrievalPolicy' {$sel:rules:DataRetrievalPolicy' :: Maybe [DataRetrievalRule]
rules = Maybe [DataRetrievalRule]
forall a. Maybe a
Prelude.Nothing}

-- | The policy rule. Although this is a list type, currently there must be
-- only one rule, which contains a Strategy field and optionally a
-- BytesPerHour field.
dataRetrievalPolicy_rules :: Lens.Lens' DataRetrievalPolicy (Prelude.Maybe [DataRetrievalRule])
dataRetrievalPolicy_rules :: (Maybe [DataRetrievalRule] -> f (Maybe [DataRetrievalRule]))
-> DataRetrievalPolicy -> f DataRetrievalPolicy
dataRetrievalPolicy_rules = (DataRetrievalPolicy -> Maybe [DataRetrievalRule])
-> (DataRetrievalPolicy
    -> Maybe [DataRetrievalRule] -> DataRetrievalPolicy)
-> Lens
     DataRetrievalPolicy
     DataRetrievalPolicy
     (Maybe [DataRetrievalRule])
     (Maybe [DataRetrievalRule])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataRetrievalPolicy' {Maybe [DataRetrievalRule]
rules :: Maybe [DataRetrievalRule]
$sel:rules:DataRetrievalPolicy' :: DataRetrievalPolicy -> Maybe [DataRetrievalRule]
rules} -> Maybe [DataRetrievalRule]
rules) (\s :: DataRetrievalPolicy
s@DataRetrievalPolicy' {} Maybe [DataRetrievalRule]
a -> DataRetrievalPolicy
s {$sel:rules:DataRetrievalPolicy' :: Maybe [DataRetrievalRule]
rules = Maybe [DataRetrievalRule]
a} :: DataRetrievalPolicy) ((Maybe [DataRetrievalRule] -> f (Maybe [DataRetrievalRule]))
 -> DataRetrievalPolicy -> f DataRetrievalPolicy)
-> ((Maybe [DataRetrievalRule] -> f (Maybe [DataRetrievalRule]))
    -> Maybe [DataRetrievalRule] -> f (Maybe [DataRetrievalRule]))
-> (Maybe [DataRetrievalRule] -> f (Maybe [DataRetrievalRule]))
-> DataRetrievalPolicy
-> f DataRetrievalPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [DataRetrievalRule]
  [DataRetrievalRule]
  [DataRetrievalRule]
  [DataRetrievalRule]
-> Iso
     (Maybe [DataRetrievalRule])
     (Maybe [DataRetrievalRule])
     (Maybe [DataRetrievalRule])
     (Maybe [DataRetrievalRule])
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
  [DataRetrievalRule]
  [DataRetrievalRule]
  [DataRetrievalRule]
  [DataRetrievalRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON DataRetrievalPolicy where
  parseJSON :: Value -> Parser DataRetrievalPolicy
parseJSON =
    String
-> (Object -> Parser DataRetrievalPolicy)
-> Value
-> Parser DataRetrievalPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DataRetrievalPolicy"
      ( \Object
x ->
          Maybe [DataRetrievalRule] -> DataRetrievalPolicy
DataRetrievalPolicy'
            (Maybe [DataRetrievalRule] -> DataRetrievalPolicy)
-> Parser (Maybe [DataRetrievalRule]) -> Parser DataRetrievalPolicy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [DataRetrievalRule]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Rules" Parser (Maybe (Maybe [DataRetrievalRule]))
-> Maybe [DataRetrievalRule] -> Parser (Maybe [DataRetrievalRule])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [DataRetrievalRule]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable DataRetrievalPolicy

instance Prelude.NFData DataRetrievalPolicy

instance Core.ToJSON DataRetrievalPolicy where
  toJSON :: DataRetrievalPolicy -> Value
toJSON DataRetrievalPolicy' {Maybe [DataRetrievalRule]
rules :: Maybe [DataRetrievalRule]
$sel:rules:DataRetrievalPolicy' :: DataRetrievalPolicy -> Maybe [DataRetrievalRule]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Rules" Text -> [DataRetrievalRule] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([DataRetrievalRule] -> Pair)
-> Maybe [DataRetrievalRule] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [DataRetrievalRule]
rules]
      )