{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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. Must contain 1 to 50 alphanumeric or
    -- \'-_.\' characters.
    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
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
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. 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. Must contain 1 to 50 alphanumeric or
-- \'-_.\' characters.
--
-- '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'
    { $sel:advancedBackupSettings:BackupPlan' :: Maybe [AdvancedBackupSetting]
advancedBackupSettings =
        forall a. Maybe a
Prelude.Nothing,
      $sel:backupPlanName:BackupPlan' :: Text
backupPlanName = Text
pBackupPlanName_,
      $sel:rules:BackupPlan' :: [BackupRule]
rules = 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 :: Lens' BackupPlan (Maybe [AdvancedBackupSetting])
backupPlan_advancedBackupSettings = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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. Must contain 1 to 50 alphanumeric or
-- \'-_.\' characters.
backupPlan_backupPlanName :: Lens.Lens' BackupPlan Prelude.Text
backupPlan_backupPlanName :: Lens' BackupPlan Text
backupPlan_backupPlanName = 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 :: Lens' BackupPlan [BackupRule]
backupPlan_rules = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON BackupPlan where
  parseJSON :: Value -> Parser BackupPlan
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"BackupPlan"
      ( \Object
x ->
          Maybe [AdvancedBackupSetting] -> Text -> [BackupRule] -> BackupPlan
BackupPlan'
            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
"AdvancedBackupSettings"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"BackupPlanName")
            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
"Rules" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable BackupPlan where
  hashWithSalt :: Int -> BackupPlan -> Int
hashWithSalt Int
_salt BackupPlan' {[BackupRule]
Maybe [AdvancedBackupSetting]
Text
rules :: [BackupRule]
backupPlanName :: Text
advancedBackupSettings :: Maybe [AdvancedBackupSetting]
$sel:rules:BackupPlan' :: BackupPlan -> [BackupRule]
$sel:backupPlanName:BackupPlan' :: BackupPlan -> Text
$sel:advancedBackupSettings:BackupPlan' :: BackupPlan -> Maybe [AdvancedBackupSetting]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [AdvancedBackupSetting]
advancedBackupSettings
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
backupPlanName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [BackupRule]
rules

instance Prelude.NFData BackupPlan where
  rnf :: BackupPlan -> ()
rnf BackupPlan' {[BackupRule]
Maybe [AdvancedBackupSetting]
Text
rules :: [BackupRule]
backupPlanName :: Text
advancedBackupSettings :: Maybe [AdvancedBackupSetting]
$sel:rules:BackupPlan' :: BackupPlan -> [BackupRule]
$sel:backupPlanName:BackupPlan' :: BackupPlan -> Text
$sel:advancedBackupSettings:BackupPlan' :: BackupPlan -> Maybe [AdvancedBackupSetting]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [AdvancedBackupSetting]
advancedBackupSettings
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
backupPlanName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BackupRule]
rules