{-# 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.Chime.Types.ChannelRetentionSettings
-- 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.Chime.Types.ChannelRetentionSettings where

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

-- | The details of the retention settings for a channel.
--
-- /See:/ 'newChannelRetentionSettings' smart constructor.
data ChannelRetentionSettings = ChannelRetentionSettings'
  { -- | The time in days to retain the messages in a channel.
    ChannelRetentionSettings -> Maybe Natural
retentionDays :: Prelude.Maybe Prelude.Natural
  }
  deriving (ChannelRetentionSettings -> ChannelRetentionSettings -> Bool
(ChannelRetentionSettings -> ChannelRetentionSettings -> Bool)
-> (ChannelRetentionSettings -> ChannelRetentionSettings -> Bool)
-> Eq ChannelRetentionSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChannelRetentionSettings -> ChannelRetentionSettings -> Bool
$c/= :: ChannelRetentionSettings -> ChannelRetentionSettings -> Bool
== :: ChannelRetentionSettings -> ChannelRetentionSettings -> Bool
$c== :: ChannelRetentionSettings -> ChannelRetentionSettings -> Bool
Prelude.Eq, ReadPrec [ChannelRetentionSettings]
ReadPrec ChannelRetentionSettings
Int -> ReadS ChannelRetentionSettings
ReadS [ChannelRetentionSettings]
(Int -> ReadS ChannelRetentionSettings)
-> ReadS [ChannelRetentionSettings]
-> ReadPrec ChannelRetentionSettings
-> ReadPrec [ChannelRetentionSettings]
-> Read ChannelRetentionSettings
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ChannelRetentionSettings]
$creadListPrec :: ReadPrec [ChannelRetentionSettings]
readPrec :: ReadPrec ChannelRetentionSettings
$creadPrec :: ReadPrec ChannelRetentionSettings
readList :: ReadS [ChannelRetentionSettings]
$creadList :: ReadS [ChannelRetentionSettings]
readsPrec :: Int -> ReadS ChannelRetentionSettings
$creadsPrec :: Int -> ReadS ChannelRetentionSettings
Prelude.Read, Int -> ChannelRetentionSettings -> ShowS
[ChannelRetentionSettings] -> ShowS
ChannelRetentionSettings -> String
(Int -> ChannelRetentionSettings -> ShowS)
-> (ChannelRetentionSettings -> String)
-> ([ChannelRetentionSettings] -> ShowS)
-> Show ChannelRetentionSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChannelRetentionSettings] -> ShowS
$cshowList :: [ChannelRetentionSettings] -> ShowS
show :: ChannelRetentionSettings -> String
$cshow :: ChannelRetentionSettings -> String
showsPrec :: Int -> ChannelRetentionSettings -> ShowS
$cshowsPrec :: Int -> ChannelRetentionSettings -> ShowS
Prelude.Show, (forall x.
 ChannelRetentionSettings -> Rep ChannelRetentionSettings x)
-> (forall x.
    Rep ChannelRetentionSettings x -> ChannelRetentionSettings)
-> Generic ChannelRetentionSettings
forall x.
Rep ChannelRetentionSettings x -> ChannelRetentionSettings
forall x.
ChannelRetentionSettings -> Rep ChannelRetentionSettings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ChannelRetentionSettings x -> ChannelRetentionSettings
$cfrom :: forall x.
ChannelRetentionSettings -> Rep ChannelRetentionSettings x
Prelude.Generic)

-- |
-- Create a value of 'ChannelRetentionSettings' 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:
--
-- 'retentionDays', 'channelRetentionSettings_retentionDays' - The time in days to retain the messages in a channel.
newChannelRetentionSettings ::
  ChannelRetentionSettings
newChannelRetentionSettings :: ChannelRetentionSettings
newChannelRetentionSettings =
  ChannelRetentionSettings' :: Maybe Natural -> ChannelRetentionSettings
ChannelRetentionSettings'
    { $sel:retentionDays:ChannelRetentionSettings' :: Maybe Natural
retentionDays =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The time in days to retain the messages in a channel.
channelRetentionSettings_retentionDays :: Lens.Lens' ChannelRetentionSettings (Prelude.Maybe Prelude.Natural)
channelRetentionSettings_retentionDays :: (Maybe Natural -> f (Maybe Natural))
-> ChannelRetentionSettings -> f ChannelRetentionSettings
channelRetentionSettings_retentionDays = (ChannelRetentionSettings -> Maybe Natural)
-> (ChannelRetentionSettings
    -> Maybe Natural -> ChannelRetentionSettings)
-> Lens
     ChannelRetentionSettings
     ChannelRetentionSettings
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChannelRetentionSettings' {Maybe Natural
retentionDays :: Maybe Natural
$sel:retentionDays:ChannelRetentionSettings' :: ChannelRetentionSettings -> Maybe Natural
retentionDays} -> Maybe Natural
retentionDays) (\s :: ChannelRetentionSettings
s@ChannelRetentionSettings' {} Maybe Natural
a -> ChannelRetentionSettings
s {$sel:retentionDays:ChannelRetentionSettings' :: Maybe Natural
retentionDays = Maybe Natural
a} :: ChannelRetentionSettings)

instance Core.FromJSON ChannelRetentionSettings where
  parseJSON :: Value -> Parser ChannelRetentionSettings
parseJSON =
    String
-> (Object -> Parser ChannelRetentionSettings)
-> Value
-> Parser ChannelRetentionSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ChannelRetentionSettings"
      ( \Object
x ->
          Maybe Natural -> ChannelRetentionSettings
ChannelRetentionSettings'
            (Maybe Natural -> ChannelRetentionSettings)
-> Parser (Maybe Natural) -> Parser ChannelRetentionSettings
forall (f :: * -> *) a b. Functor 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
"RetentionDays")
      )

instance Prelude.Hashable ChannelRetentionSettings

instance Prelude.NFData ChannelRetentionSettings

instance Core.ToJSON ChannelRetentionSettings where
  toJSON :: ChannelRetentionSettings -> Value
toJSON ChannelRetentionSettings' {Maybe Natural
retentionDays :: Maybe Natural
$sel:retentionDays:ChannelRetentionSettings' :: ChannelRetentionSettings -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RetentionDays" 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
retentionDays
          ]
      )