{-# 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.IoTAnalytics.Types.RetentionPeriod
-- 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.IoTAnalytics.Types.RetentionPeriod where

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

-- | How long, in days, message data is kept.
--
-- /See:/ 'newRetentionPeriod' smart constructor.
data RetentionPeriod = RetentionPeriod'
  { -- | If true, message data is kept indefinitely.
    RetentionPeriod -> Maybe Bool
unlimited :: Prelude.Maybe Prelude.Bool,
    -- | The number of days that message data is kept. The @unlimited@ parameter
    -- must be false.
    RetentionPeriod -> Maybe Natural
numberOfDays :: Prelude.Maybe Prelude.Natural
  }
  deriving (RetentionPeriod -> RetentionPeriod -> Bool
(RetentionPeriod -> RetentionPeriod -> Bool)
-> (RetentionPeriod -> RetentionPeriod -> Bool)
-> Eq RetentionPeriod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RetentionPeriod -> RetentionPeriod -> Bool
$c/= :: RetentionPeriod -> RetentionPeriod -> Bool
== :: RetentionPeriod -> RetentionPeriod -> Bool
$c== :: RetentionPeriod -> RetentionPeriod -> Bool
Prelude.Eq, ReadPrec [RetentionPeriod]
ReadPrec RetentionPeriod
Int -> ReadS RetentionPeriod
ReadS [RetentionPeriod]
(Int -> ReadS RetentionPeriod)
-> ReadS [RetentionPeriod]
-> ReadPrec RetentionPeriod
-> ReadPrec [RetentionPeriod]
-> Read RetentionPeriod
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RetentionPeriod]
$creadListPrec :: ReadPrec [RetentionPeriod]
readPrec :: ReadPrec RetentionPeriod
$creadPrec :: ReadPrec RetentionPeriod
readList :: ReadS [RetentionPeriod]
$creadList :: ReadS [RetentionPeriod]
readsPrec :: Int -> ReadS RetentionPeriod
$creadsPrec :: Int -> ReadS RetentionPeriod
Prelude.Read, Int -> RetentionPeriod -> ShowS
[RetentionPeriod] -> ShowS
RetentionPeriod -> String
(Int -> RetentionPeriod -> ShowS)
-> (RetentionPeriod -> String)
-> ([RetentionPeriod] -> ShowS)
-> Show RetentionPeriod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RetentionPeriod] -> ShowS
$cshowList :: [RetentionPeriod] -> ShowS
show :: RetentionPeriod -> String
$cshow :: RetentionPeriod -> String
showsPrec :: Int -> RetentionPeriod -> ShowS
$cshowsPrec :: Int -> RetentionPeriod -> ShowS
Prelude.Show, (forall x. RetentionPeriod -> Rep RetentionPeriod x)
-> (forall x. Rep RetentionPeriod x -> RetentionPeriod)
-> Generic RetentionPeriod
forall x. Rep RetentionPeriod x -> RetentionPeriod
forall x. RetentionPeriod -> Rep RetentionPeriod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RetentionPeriod x -> RetentionPeriod
$cfrom :: forall x. RetentionPeriod -> Rep RetentionPeriod x
Prelude.Generic)

-- |
-- Create a value of 'RetentionPeriod' 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:
--
-- 'unlimited', 'retentionPeriod_unlimited' - If true, message data is kept indefinitely.
--
-- 'numberOfDays', 'retentionPeriod_numberOfDays' - The number of days that message data is kept. The @unlimited@ parameter
-- must be false.
newRetentionPeriod ::
  RetentionPeriod
newRetentionPeriod :: RetentionPeriod
newRetentionPeriod =
  RetentionPeriod' :: Maybe Bool -> Maybe Natural -> RetentionPeriod
RetentionPeriod'
    { $sel:unlimited:RetentionPeriod' :: Maybe Bool
unlimited = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:numberOfDays:RetentionPeriod' :: Maybe Natural
numberOfDays = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | If true, message data is kept indefinitely.
retentionPeriod_unlimited :: Lens.Lens' RetentionPeriod (Prelude.Maybe Prelude.Bool)
retentionPeriod_unlimited :: (Maybe Bool -> f (Maybe Bool))
-> RetentionPeriod -> f RetentionPeriod
retentionPeriod_unlimited = (RetentionPeriod -> Maybe Bool)
-> (RetentionPeriod -> Maybe Bool -> RetentionPeriod)
-> Lens RetentionPeriod RetentionPeriod (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetentionPeriod' {Maybe Bool
unlimited :: Maybe Bool
$sel:unlimited:RetentionPeriod' :: RetentionPeriod -> Maybe Bool
unlimited} -> Maybe Bool
unlimited) (\s :: RetentionPeriod
s@RetentionPeriod' {} Maybe Bool
a -> RetentionPeriod
s {$sel:unlimited:RetentionPeriod' :: Maybe Bool
unlimited = Maybe Bool
a} :: RetentionPeriod)

-- | The number of days that message data is kept. The @unlimited@ parameter
-- must be false.
retentionPeriod_numberOfDays :: Lens.Lens' RetentionPeriod (Prelude.Maybe Prelude.Natural)
retentionPeriod_numberOfDays :: (Maybe Natural -> f (Maybe Natural))
-> RetentionPeriod -> f RetentionPeriod
retentionPeriod_numberOfDays = (RetentionPeriod -> Maybe Natural)
-> (RetentionPeriod -> Maybe Natural -> RetentionPeriod)
-> Lens
     RetentionPeriod RetentionPeriod (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetentionPeriod' {Maybe Natural
numberOfDays :: Maybe Natural
$sel:numberOfDays:RetentionPeriod' :: RetentionPeriod -> Maybe Natural
numberOfDays} -> Maybe Natural
numberOfDays) (\s :: RetentionPeriod
s@RetentionPeriod' {} Maybe Natural
a -> RetentionPeriod
s {$sel:numberOfDays:RetentionPeriod' :: Maybe Natural
numberOfDays = Maybe Natural
a} :: RetentionPeriod)

instance Core.FromJSON RetentionPeriod where
  parseJSON :: Value -> Parser RetentionPeriod
parseJSON =
    String
-> (Object -> Parser RetentionPeriod)
-> Value
-> Parser RetentionPeriod
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RetentionPeriod"
      ( \Object
x ->
          Maybe Bool -> Maybe Natural -> RetentionPeriod
RetentionPeriod'
            (Maybe Bool -> Maybe Natural -> RetentionPeriod)
-> Parser (Maybe Bool) -> Parser (Maybe Natural -> RetentionPeriod)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"unlimited")
            Parser (Maybe Natural -> RetentionPeriod)
-> Parser (Maybe Natural) -> Parser RetentionPeriod
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"numberOfDays")
      )

instance Prelude.Hashable RetentionPeriod

instance Prelude.NFData RetentionPeriod

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