{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoTAnalytics.Types.RetentionPeriod where

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

-- | How long, in days, message data is kept.
--
-- /See:/ 'newRetentionPeriod' smart constructor.
data RetentionPeriod = RetentionPeriod'
  { -- | The number of days that message data is kept. The @unlimited@ parameter
    -- must be false.
    RetentionPeriod -> Maybe Natural
numberOfDays :: Prelude.Maybe Prelude.Natural,
    -- | If true, message data is kept indefinitely.
    RetentionPeriod -> Maybe Bool
unlimited :: Prelude.Maybe Prelude.Bool
  }
  deriving (RetentionPeriod -> RetentionPeriod -> Bool
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]
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
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. 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:
--
-- 'numberOfDays', 'retentionPeriod_numberOfDays' - The number of days that message data is kept. The @unlimited@ parameter
-- must be false.
--
-- 'unlimited', 'retentionPeriod_unlimited' - If true, message data is kept indefinitely.
newRetentionPeriod ::
  RetentionPeriod
newRetentionPeriod :: RetentionPeriod
newRetentionPeriod =
  RetentionPeriod'
    { $sel:numberOfDays:RetentionPeriod' :: Maybe Natural
numberOfDays = forall a. Maybe a
Prelude.Nothing,
      $sel:unlimited:RetentionPeriod' :: Maybe Bool
unlimited = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' RetentionPeriod (Maybe Natural)
retentionPeriod_numberOfDays = 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)

-- | If true, message data is kept indefinitely.
retentionPeriod_unlimited :: Lens.Lens' RetentionPeriod (Prelude.Maybe Prelude.Bool)
retentionPeriod_unlimited :: Lens' RetentionPeriod (Maybe Bool)
retentionPeriod_unlimited = 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)

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

instance Prelude.Hashable RetentionPeriod where
  hashWithSalt :: Int -> RetentionPeriod -> Int
hashWithSalt Int
_salt RetentionPeriod' {Maybe Bool
Maybe Natural
unlimited :: Maybe Bool
numberOfDays :: Maybe Natural
$sel:unlimited:RetentionPeriod' :: RetentionPeriod -> Maybe Bool
$sel:numberOfDays:RetentionPeriod' :: RetentionPeriod -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
numberOfDays
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
unlimited

instance Prelude.NFData RetentionPeriod where
  rnf :: RetentionPeriod -> ()
rnf RetentionPeriod' {Maybe Bool
Maybe Natural
unlimited :: Maybe Bool
numberOfDays :: Maybe Natural
$sel:unlimited:RetentionPeriod' :: RetentionPeriod -> Maybe Bool
$sel:numberOfDays:RetentionPeriod' :: RetentionPeriod -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
numberOfDays
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
unlimited

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