{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WorkMail.Types.FolderConfiguration 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
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
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]
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
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. 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'
    { $sel:period:FolderConfiguration' :: Maybe Natural
period = 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 :: Lens' FolderConfiguration (Maybe Natural)
folderConfiguration_period = 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 :: Lens' FolderConfiguration FolderName
folderConfiguration_name = 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 :: Lens' FolderConfiguration RetentionAction
folderConfiguration_action = 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 Data.FromJSON FolderConfiguration where
  parseJSON :: Value -> Parser FolderConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FolderConfiguration"
      ( \Object
x ->
          Maybe Natural
-> FolderName -> RetentionAction -> FolderConfiguration
FolderConfiguration'
            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
"Period")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Action")
      )

instance Prelude.Hashable FolderConfiguration where
  hashWithSalt :: Int -> FolderConfiguration -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
period
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FolderName
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RetentionAction
action

instance Prelude.NFData FolderConfiguration where
  rnf :: FolderConfiguration -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
period
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FolderName
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf RetentionAction
action

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Period" 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
period,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FolderName
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Action" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= RetentionAction
action)
          ]
      )