{-# 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.Backup.Types.BackupPlan
-- 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.Backup.Types.BackupPlan where

import Amazonka.Backup.Types.AdvancedBackupSetting
import Amazonka.Backup.Types.BackupRule
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains an optional backup plan display name and an array of
-- @BackupRule@ objects, each of which specifies a backup rule. Each rule
-- in a backup plan is a separate scheduled task and can back up a
-- different selection of Amazon Web Services resources.
--
-- /See:/ 'newBackupPlan' smart constructor.
data BackupPlan = BackupPlan'
  { -- | Contains a list of @BackupOptions@ for each resource type.
    BackupPlan -> Maybe [AdvancedBackupSetting]
advancedBackupSettings :: Prelude.Maybe [AdvancedBackupSetting],
    -- | The display name of a backup plan.
    BackupPlan -> Text
backupPlanName :: Prelude.Text,
    -- | An array of @BackupRule@ objects, each of which specifies a scheduled
    -- task that is used to back up a selection of resources.
    BackupPlan -> [BackupRule]
rules :: [BackupRule]
  }
  deriving (BackupPlan -> BackupPlan -> Bool
(BackupPlan -> BackupPlan -> Bool)
-> (BackupPlan -> BackupPlan -> Bool) -> Eq BackupPlan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BackupPlan -> BackupPlan -> Bool
$c/= :: BackupPlan -> BackupPlan -> Bool
== :: BackupPlan -> BackupPlan -> Bool
$c== :: BackupPlan -> BackupPlan -> Bool
Prelude.Eq, Int -> BackupPlan -> ShowS
[BackupPlan] -> ShowS
BackupPlan -> String
(Int -> BackupPlan -> ShowS)
-> (BackupPlan -> String)
-> ([BackupPlan] -> ShowS)
-> Show BackupPlan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BackupPlan] -> ShowS
$cshowList :: [BackupPlan] -> ShowS
show :: BackupPlan -> String
$cshow :: BackupPlan -> String
showsPrec :: Int -> BackupPlan -> ShowS
$cshowsPrec :: Int -> BackupPlan -> ShowS
Prelude.Show, (forall x. BackupPlan -> Rep BackupPlan x)
-> (forall x. Rep BackupPlan x -> BackupPlan) -> Generic BackupPlan
forall x. Rep BackupPlan x -> BackupPlan
forall x. BackupPlan -> Rep BackupPlan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BackupPlan x -> BackupPlan
$cfrom :: forall x. BackupPlan -> Rep BackupPlan x
Prelude.Generic)

-- |
-- Create a value of 'BackupPlan' 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:
--
-- 'advancedBackupSettings', 'backupPlan_advancedBackupSettings' - Contains a list of @BackupOptions@ for each resource type.
--
-- 'backupPlanName', 'backupPlan_backupPlanName' - The display name of a backup plan.
--
-- 'rules', 'backupPlan_rules' - An array of @BackupRule@ objects, each of which specifies a scheduled
-- task that is used to back up a selection of resources.
newBackupPlan ::
  -- | 'backupPlanName'
  Prelude.Text ->
  BackupPlan
newBackupPlan :: Text -> BackupPlan
newBackupPlan Text
pBackupPlanName_ =
  BackupPlan' :: Maybe [AdvancedBackupSetting] -> Text -> [BackupRule] -> BackupPlan
BackupPlan'
    { $sel:advancedBackupSettings:BackupPlan' :: Maybe [AdvancedBackupSetting]
advancedBackupSettings =
        Maybe [AdvancedBackupSetting]
forall a. Maybe a
Prelude.Nothing,
      $sel:backupPlanName:BackupPlan' :: Text
backupPlanName = Text
pBackupPlanName_,
      $sel:rules:BackupPlan' :: [BackupRule]
rules = [BackupRule]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Contains a list of @BackupOptions@ for each resource type.
backupPlan_advancedBackupSettings :: Lens.Lens' BackupPlan (Prelude.Maybe [AdvancedBackupSetting])
backupPlan_advancedBackupSettings :: (Maybe [AdvancedBackupSetting]
 -> f (Maybe [AdvancedBackupSetting]))
-> BackupPlan -> f BackupPlan
backupPlan_advancedBackupSettings = (BackupPlan -> Maybe [AdvancedBackupSetting])
-> (BackupPlan -> Maybe [AdvancedBackupSetting] -> BackupPlan)
-> Lens
     BackupPlan
     BackupPlan
     (Maybe [AdvancedBackupSetting])
     (Maybe [AdvancedBackupSetting])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BackupPlan' {Maybe [AdvancedBackupSetting]
advancedBackupSettings :: Maybe [AdvancedBackupSetting]
$sel:advancedBackupSettings:BackupPlan' :: BackupPlan -> Maybe [AdvancedBackupSetting]
advancedBackupSettings} -> Maybe [AdvancedBackupSetting]
advancedBackupSettings) (\s :: BackupPlan
s@BackupPlan' {} Maybe [AdvancedBackupSetting]
a -> BackupPlan
s {$sel:advancedBackupSettings:BackupPlan' :: Maybe [AdvancedBackupSetting]
advancedBackupSettings = Maybe [AdvancedBackupSetting]
a} :: BackupPlan) ((Maybe [AdvancedBackupSetting]
  -> f (Maybe [AdvancedBackupSetting]))
 -> BackupPlan -> f BackupPlan)
-> ((Maybe [AdvancedBackupSetting]
     -> f (Maybe [AdvancedBackupSetting]))
    -> Maybe [AdvancedBackupSetting]
    -> f (Maybe [AdvancedBackupSetting]))
-> (Maybe [AdvancedBackupSetting]
    -> f (Maybe [AdvancedBackupSetting]))
-> BackupPlan
-> f BackupPlan
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [AdvancedBackupSetting]
  [AdvancedBackupSetting]
  [AdvancedBackupSetting]
  [AdvancedBackupSetting]
-> Iso
     (Maybe [AdvancedBackupSetting])
     (Maybe [AdvancedBackupSetting])
     (Maybe [AdvancedBackupSetting])
     (Maybe [AdvancedBackupSetting])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [AdvancedBackupSetting]
  [AdvancedBackupSetting]
  [AdvancedBackupSetting]
  [AdvancedBackupSetting]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The display name of a backup plan.
backupPlan_backupPlanName :: Lens.Lens' BackupPlan Prelude.Text
backupPlan_backupPlanName :: (Text -> f Text) -> BackupPlan -> f BackupPlan
backupPlan_backupPlanName = (BackupPlan -> Text)
-> (BackupPlan -> Text -> BackupPlan)
-> Lens BackupPlan BackupPlan Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BackupPlan' {Text
backupPlanName :: Text
$sel:backupPlanName:BackupPlan' :: BackupPlan -> Text
backupPlanName} -> Text
backupPlanName) (\s :: BackupPlan
s@BackupPlan' {} Text
a -> BackupPlan
s {$sel:backupPlanName:BackupPlan' :: Text
backupPlanName = Text
a} :: BackupPlan)

-- | An array of @BackupRule@ objects, each of which specifies a scheduled
-- task that is used to back up a selection of resources.
backupPlan_rules :: Lens.Lens' BackupPlan [BackupRule]
backupPlan_rules :: ([BackupRule] -> f [BackupRule]) -> BackupPlan -> f BackupPlan
backupPlan_rules = (BackupPlan -> [BackupRule])
-> (BackupPlan -> [BackupRule] -> BackupPlan)
-> Lens BackupPlan BackupPlan [BackupRule] [BackupRule]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BackupPlan' {[BackupRule]
rules :: [BackupRule]
$sel:rules:BackupPlan' :: BackupPlan -> [BackupRule]
rules} -> [BackupRule]
rules) (\s :: BackupPlan
s@BackupPlan' {} [BackupRule]
a -> BackupPlan
s {$sel:rules:BackupPlan' :: [BackupRule]
rules = [BackupRule]
a} :: BackupPlan) (([BackupRule] -> f [BackupRule]) -> BackupPlan -> f BackupPlan)
-> (([BackupRule] -> f [BackupRule])
    -> [BackupRule] -> f [BackupRule])
-> ([BackupRule] -> f [BackupRule])
-> BackupPlan
-> f BackupPlan
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([BackupRule] -> f [BackupRule]) -> [BackupRule] -> f [BackupRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON BackupPlan where
  parseJSON :: Value -> Parser BackupPlan
parseJSON =
    String
-> (Object -> Parser BackupPlan) -> Value -> Parser BackupPlan
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"BackupPlan"
      ( \Object
x ->
          Maybe [AdvancedBackupSetting] -> Text -> [BackupRule] -> BackupPlan
BackupPlan'
            (Maybe [AdvancedBackupSetting]
 -> Text -> [BackupRule] -> BackupPlan)
-> Parser (Maybe [AdvancedBackupSetting])
-> Parser (Text -> [BackupRule] -> BackupPlan)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [AdvancedBackupSetting]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AdvancedBackupSettings"
                            Parser (Maybe (Maybe [AdvancedBackupSetting]))
-> Maybe [AdvancedBackupSetting]
-> Parser (Maybe [AdvancedBackupSetting])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [AdvancedBackupSetting]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Text -> [BackupRule] -> BackupPlan)
-> Parser Text -> Parser ([BackupRule] -> BackupPlan)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"BackupPlanName")
            Parser ([BackupRule] -> BackupPlan)
-> Parser [BackupRule] -> Parser BackupPlan
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [BackupRule])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Rules" Parser (Maybe [BackupRule]) -> [BackupRule] -> Parser [BackupRule]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [BackupRule]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable BackupPlan

instance Prelude.NFData BackupPlan