{-# 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.WorkMail.Types.FolderConfiguration
-- 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.WorkMail.Types.FolderConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WorkMail.Types.FolderName
import Amazonka.WorkMail.Types.RetentionAction

-- | The configuration applied to an organization\'s folders by its retention
-- policy.
--
-- /See:/ 'newFolderConfiguration' smart constructor.
data FolderConfiguration = FolderConfiguration'
  { -- | The number of days for which the folder-configuration action applies.
    FolderConfiguration -> Maybe Natural
period :: Prelude.Maybe Prelude.Natural,
    -- | The folder name.
    FolderConfiguration -> FolderName
name :: FolderName,
    -- | The action to take on the folder contents at the end of the folder
    -- configuration period.
    FolderConfiguration -> RetentionAction
action :: RetentionAction
  }
  deriving (FolderConfiguration -> FolderConfiguration -> Bool
(FolderConfiguration -> FolderConfiguration -> Bool)
-> (FolderConfiguration -> FolderConfiguration -> Bool)
-> Eq FolderConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FolderConfiguration -> FolderConfiguration -> Bool
$c/= :: FolderConfiguration -> FolderConfiguration -> Bool
== :: FolderConfiguration -> FolderConfiguration -> Bool
$c== :: FolderConfiguration -> FolderConfiguration -> Bool
Prelude.Eq, ReadPrec [FolderConfiguration]
ReadPrec FolderConfiguration
Int -> ReadS FolderConfiguration
ReadS [FolderConfiguration]
(Int -> ReadS FolderConfiguration)
-> ReadS [FolderConfiguration]
-> ReadPrec FolderConfiguration
-> ReadPrec [FolderConfiguration]
-> Read FolderConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FolderConfiguration]
$creadListPrec :: ReadPrec [FolderConfiguration]
readPrec :: ReadPrec FolderConfiguration
$creadPrec :: ReadPrec FolderConfiguration
readList :: ReadS [FolderConfiguration]
$creadList :: ReadS [FolderConfiguration]
readsPrec :: Int -> ReadS FolderConfiguration
$creadsPrec :: Int -> ReadS FolderConfiguration
Prelude.Read, Int -> FolderConfiguration -> ShowS
[FolderConfiguration] -> ShowS
FolderConfiguration -> String
(Int -> FolderConfiguration -> ShowS)
-> (FolderConfiguration -> String)
-> ([FolderConfiguration] -> ShowS)
-> Show FolderConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FolderConfiguration] -> ShowS
$cshowList :: [FolderConfiguration] -> ShowS
show :: FolderConfiguration -> String
$cshow :: FolderConfiguration -> String
showsPrec :: Int -> FolderConfiguration -> ShowS
$cshowsPrec :: Int -> FolderConfiguration -> ShowS
Prelude.Show, (forall x. FolderConfiguration -> Rep FolderConfiguration x)
-> (forall x. Rep FolderConfiguration x -> FolderConfiguration)
-> Generic FolderConfiguration
forall x. Rep FolderConfiguration x -> FolderConfiguration
forall x. FolderConfiguration -> Rep FolderConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FolderConfiguration x -> FolderConfiguration
$cfrom :: forall x. FolderConfiguration -> Rep FolderConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'FolderConfiguration' 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:
--
-- 'period', 'folderConfiguration_period' - The number of days for which the folder-configuration action applies.
--
-- 'name', 'folderConfiguration_name' - The folder name.
--
-- 'action', 'folderConfiguration_action' - The action to take on the folder contents at the end of the folder
-- configuration period.
newFolderConfiguration ::
  -- | 'name'
  FolderName ->
  -- | 'action'
  RetentionAction ->
  FolderConfiguration
newFolderConfiguration :: FolderName -> RetentionAction -> FolderConfiguration
newFolderConfiguration FolderName
pName_ RetentionAction
pAction_ =
  FolderConfiguration' :: Maybe Natural
-> FolderName -> RetentionAction -> FolderConfiguration
FolderConfiguration'
    { $sel:period:FolderConfiguration' :: Maybe Natural
period = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:name:FolderConfiguration' :: FolderName
name = FolderName
pName_,
      $sel:action:FolderConfiguration' :: RetentionAction
action = RetentionAction
pAction_
    }

-- | The number of days for which the folder-configuration action applies.
folderConfiguration_period :: Lens.Lens' FolderConfiguration (Prelude.Maybe Prelude.Natural)
folderConfiguration_period :: (Maybe Natural -> f (Maybe Natural))
-> FolderConfiguration -> f FolderConfiguration
folderConfiguration_period = (FolderConfiguration -> Maybe Natural)
-> (FolderConfiguration -> Maybe Natural -> FolderConfiguration)
-> Lens
     FolderConfiguration
     FolderConfiguration
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FolderConfiguration' {Maybe Natural
period :: Maybe Natural
$sel:period:FolderConfiguration' :: FolderConfiguration -> Maybe Natural
period} -> Maybe Natural
period) (\s :: FolderConfiguration
s@FolderConfiguration' {} Maybe Natural
a -> FolderConfiguration
s {$sel:period:FolderConfiguration' :: Maybe Natural
period = Maybe Natural
a} :: FolderConfiguration)

-- | The folder name.
folderConfiguration_name :: Lens.Lens' FolderConfiguration FolderName
folderConfiguration_name :: (FolderName -> f FolderName)
-> FolderConfiguration -> f FolderConfiguration
folderConfiguration_name = (FolderConfiguration -> FolderName)
-> (FolderConfiguration -> FolderName -> FolderConfiguration)
-> Lens
     FolderConfiguration FolderConfiguration FolderName FolderName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FolderConfiguration' {FolderName
name :: FolderName
$sel:name:FolderConfiguration' :: FolderConfiguration -> FolderName
name} -> FolderName
name) (\s :: FolderConfiguration
s@FolderConfiguration' {} FolderName
a -> FolderConfiguration
s {$sel:name:FolderConfiguration' :: FolderName
name = FolderName
a} :: FolderConfiguration)

-- | The action to take on the folder contents at the end of the folder
-- configuration period.
folderConfiguration_action :: Lens.Lens' FolderConfiguration RetentionAction
folderConfiguration_action :: (RetentionAction -> f RetentionAction)
-> FolderConfiguration -> f FolderConfiguration
folderConfiguration_action = (FolderConfiguration -> RetentionAction)
-> (FolderConfiguration -> RetentionAction -> FolderConfiguration)
-> Lens
     FolderConfiguration
     FolderConfiguration
     RetentionAction
     RetentionAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FolderConfiguration' {RetentionAction
action :: RetentionAction
$sel:action:FolderConfiguration' :: FolderConfiguration -> RetentionAction
action} -> RetentionAction
action) (\s :: FolderConfiguration
s@FolderConfiguration' {} RetentionAction
a -> FolderConfiguration
s {$sel:action:FolderConfiguration' :: RetentionAction
action = RetentionAction
a} :: FolderConfiguration)

instance Core.FromJSON FolderConfiguration where
  parseJSON :: Value -> Parser FolderConfiguration
parseJSON =
    String
-> (Object -> Parser FolderConfiguration)
-> Value
-> Parser FolderConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FolderConfiguration"
      ( \Object
x ->
          Maybe Natural
-> FolderName -> RetentionAction -> FolderConfiguration
FolderConfiguration'
            (Maybe Natural
 -> FolderName -> RetentionAction -> FolderConfiguration)
-> Parser (Maybe Natural)
-> Parser (FolderName -> RetentionAction -> FolderConfiguration)
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
"Period")
            Parser (FolderName -> RetentionAction -> FolderConfiguration)
-> Parser FolderName
-> Parser (RetentionAction -> FolderConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser FolderName
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
            Parser (RetentionAction -> FolderConfiguration)
-> Parser RetentionAction -> Parser FolderConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser RetentionAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Action")
      )

instance Prelude.Hashable FolderConfiguration

instance Prelude.NFData FolderConfiguration

instance Core.ToJSON FolderConfiguration where
  toJSON :: FolderConfiguration -> Value
toJSON FolderConfiguration' {Maybe Natural
FolderName
RetentionAction
action :: RetentionAction
name :: FolderName
period :: Maybe Natural
$sel:action:FolderConfiguration' :: FolderConfiguration -> RetentionAction
$sel:name:FolderConfiguration' :: FolderConfiguration -> FolderName
$sel:period:FolderConfiguration' :: FolderConfiguration -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Period" 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
period,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> FolderName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= FolderName
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Action" Text -> RetentionAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RetentionAction
action)
          ]
      )