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

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

-- | Data retrieval policy rule.
--
-- /See:/ 'newDataRetrievalRule' smart constructor.
data DataRetrievalRule = DataRetrievalRule'
  { -- | The type of data retrieval policy to set.
    --
    -- Valid values: BytesPerHour|FreeTier|None
    DataRetrievalRule -> Maybe Text
strategy :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of bytes that can be retrieved in an hour.
    --
    -- This field is required only if the value of the Strategy field is
    -- @BytesPerHour@. Your PUT operation will be rejected if the Strategy
    -- field is not set to @BytesPerHour@ and you set this field.
    DataRetrievalRule -> Maybe Integer
bytesPerHour :: Prelude.Maybe Prelude.Integer
  }
  deriving (DataRetrievalRule -> DataRetrievalRule -> Bool
(DataRetrievalRule -> DataRetrievalRule -> Bool)
-> (DataRetrievalRule -> DataRetrievalRule -> Bool)
-> Eq DataRetrievalRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataRetrievalRule -> DataRetrievalRule -> Bool
$c/= :: DataRetrievalRule -> DataRetrievalRule -> Bool
== :: DataRetrievalRule -> DataRetrievalRule -> Bool
$c== :: DataRetrievalRule -> DataRetrievalRule -> Bool
Prelude.Eq, ReadPrec [DataRetrievalRule]
ReadPrec DataRetrievalRule
Int -> ReadS DataRetrievalRule
ReadS [DataRetrievalRule]
(Int -> ReadS DataRetrievalRule)
-> ReadS [DataRetrievalRule]
-> ReadPrec DataRetrievalRule
-> ReadPrec [DataRetrievalRule]
-> Read DataRetrievalRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DataRetrievalRule]
$creadListPrec :: ReadPrec [DataRetrievalRule]
readPrec :: ReadPrec DataRetrievalRule
$creadPrec :: ReadPrec DataRetrievalRule
readList :: ReadS [DataRetrievalRule]
$creadList :: ReadS [DataRetrievalRule]
readsPrec :: Int -> ReadS DataRetrievalRule
$creadsPrec :: Int -> ReadS DataRetrievalRule
Prelude.Read, Int -> DataRetrievalRule -> ShowS
[DataRetrievalRule] -> ShowS
DataRetrievalRule -> String
(Int -> DataRetrievalRule -> ShowS)
-> (DataRetrievalRule -> String)
-> ([DataRetrievalRule] -> ShowS)
-> Show DataRetrievalRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataRetrievalRule] -> ShowS
$cshowList :: [DataRetrievalRule] -> ShowS
show :: DataRetrievalRule -> String
$cshow :: DataRetrievalRule -> String
showsPrec :: Int -> DataRetrievalRule -> ShowS
$cshowsPrec :: Int -> DataRetrievalRule -> ShowS
Prelude.Show, (forall x. DataRetrievalRule -> Rep DataRetrievalRule x)
-> (forall x. Rep DataRetrievalRule x -> DataRetrievalRule)
-> Generic DataRetrievalRule
forall x. Rep DataRetrievalRule x -> DataRetrievalRule
forall x. DataRetrievalRule -> Rep DataRetrievalRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DataRetrievalRule x -> DataRetrievalRule
$cfrom :: forall x. DataRetrievalRule -> Rep DataRetrievalRule x
Prelude.Generic)

-- |
-- Create a value of 'DataRetrievalRule' 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:
--
-- 'strategy', 'dataRetrievalRule_strategy' - The type of data retrieval policy to set.
--
-- Valid values: BytesPerHour|FreeTier|None
--
-- 'bytesPerHour', 'dataRetrievalRule_bytesPerHour' - The maximum number of bytes that can be retrieved in an hour.
--
-- This field is required only if the value of the Strategy field is
-- @BytesPerHour@. Your PUT operation will be rejected if the Strategy
-- field is not set to @BytesPerHour@ and you set this field.
newDataRetrievalRule ::
  DataRetrievalRule
newDataRetrievalRule :: DataRetrievalRule
newDataRetrievalRule =
  DataRetrievalRule' :: Maybe Text -> Maybe Integer -> DataRetrievalRule
DataRetrievalRule'
    { $sel:strategy:DataRetrievalRule' :: Maybe Text
strategy = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bytesPerHour:DataRetrievalRule' :: Maybe Integer
bytesPerHour = Maybe Integer
forall a. Maybe a
Prelude.Nothing
    }

-- | The type of data retrieval policy to set.
--
-- Valid values: BytesPerHour|FreeTier|None
dataRetrievalRule_strategy :: Lens.Lens' DataRetrievalRule (Prelude.Maybe Prelude.Text)
dataRetrievalRule_strategy :: (Maybe Text -> f (Maybe Text))
-> DataRetrievalRule -> f DataRetrievalRule
dataRetrievalRule_strategy = (DataRetrievalRule -> Maybe Text)
-> (DataRetrievalRule -> Maybe Text -> DataRetrievalRule)
-> Lens
     DataRetrievalRule DataRetrievalRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataRetrievalRule' {Maybe Text
strategy :: Maybe Text
$sel:strategy:DataRetrievalRule' :: DataRetrievalRule -> Maybe Text
strategy} -> Maybe Text
strategy) (\s :: DataRetrievalRule
s@DataRetrievalRule' {} Maybe Text
a -> DataRetrievalRule
s {$sel:strategy:DataRetrievalRule' :: Maybe Text
strategy = Maybe Text
a} :: DataRetrievalRule)

-- | The maximum number of bytes that can be retrieved in an hour.
--
-- This field is required only if the value of the Strategy field is
-- @BytesPerHour@. Your PUT operation will be rejected if the Strategy
-- field is not set to @BytesPerHour@ and you set this field.
dataRetrievalRule_bytesPerHour :: Lens.Lens' DataRetrievalRule (Prelude.Maybe Prelude.Integer)
dataRetrievalRule_bytesPerHour :: (Maybe Integer -> f (Maybe Integer))
-> DataRetrievalRule -> f DataRetrievalRule
dataRetrievalRule_bytesPerHour = (DataRetrievalRule -> Maybe Integer)
-> (DataRetrievalRule -> Maybe Integer -> DataRetrievalRule)
-> Lens
     DataRetrievalRule DataRetrievalRule (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataRetrievalRule' {Maybe Integer
bytesPerHour :: Maybe Integer
$sel:bytesPerHour:DataRetrievalRule' :: DataRetrievalRule -> Maybe Integer
bytesPerHour} -> Maybe Integer
bytesPerHour) (\s :: DataRetrievalRule
s@DataRetrievalRule' {} Maybe Integer
a -> DataRetrievalRule
s {$sel:bytesPerHour:DataRetrievalRule' :: Maybe Integer
bytesPerHour = Maybe Integer
a} :: DataRetrievalRule)

instance Core.FromJSON DataRetrievalRule where
  parseJSON :: Value -> Parser DataRetrievalRule
parseJSON =
    String
-> (Object -> Parser DataRetrievalRule)
-> Value
-> Parser DataRetrievalRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DataRetrievalRule"
      ( \Object
x ->
          Maybe Text -> Maybe Integer -> DataRetrievalRule
DataRetrievalRule'
            (Maybe Text -> Maybe Integer -> DataRetrievalRule)
-> Parser (Maybe Text)
-> Parser (Maybe Integer -> DataRetrievalRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Strategy")
            Parser (Maybe Integer -> DataRetrievalRule)
-> Parser (Maybe Integer) -> Parser DataRetrievalRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"BytesPerHour")
      )

instance Prelude.Hashable DataRetrievalRule

instance Prelude.NFData DataRetrievalRule

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