{-# 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.DLM.Types.ArchiveRule
-- 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.DLM.Types.ArchiveRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import Amazonka.DLM.Types.ArchiveRetainRule
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | __[Snapshot policies only]__ Specifies a snapshot archiving rule for a
-- schedule.
--
-- /See:/ 'newArchiveRule' smart constructor.
data ArchiveRule = ArchiveRule'
  { -- | Information about the retention period for the snapshot archiving rule.
    ArchiveRule -> ArchiveRetainRule
retainRule :: ArchiveRetainRule
  }
  deriving (ArchiveRule -> ArchiveRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArchiveRule -> ArchiveRule -> Bool
$c/= :: ArchiveRule -> ArchiveRule -> Bool
== :: ArchiveRule -> ArchiveRule -> Bool
$c== :: ArchiveRule -> ArchiveRule -> Bool
Prelude.Eq, ReadPrec [ArchiveRule]
ReadPrec ArchiveRule
Int -> ReadS ArchiveRule
ReadS [ArchiveRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ArchiveRule]
$creadListPrec :: ReadPrec [ArchiveRule]
readPrec :: ReadPrec ArchiveRule
$creadPrec :: ReadPrec ArchiveRule
readList :: ReadS [ArchiveRule]
$creadList :: ReadS [ArchiveRule]
readsPrec :: Int -> ReadS ArchiveRule
$creadsPrec :: Int -> ReadS ArchiveRule
Prelude.Read, Int -> ArchiveRule -> ShowS
[ArchiveRule] -> ShowS
ArchiveRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArchiveRule] -> ShowS
$cshowList :: [ArchiveRule] -> ShowS
show :: ArchiveRule -> String
$cshow :: ArchiveRule -> String
showsPrec :: Int -> ArchiveRule -> ShowS
$cshowsPrec :: Int -> ArchiveRule -> ShowS
Prelude.Show, forall x. Rep ArchiveRule x -> ArchiveRule
forall x. ArchiveRule -> Rep ArchiveRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ArchiveRule x -> ArchiveRule
$cfrom :: forall x. ArchiveRule -> Rep ArchiveRule x
Prelude.Generic)

-- |
-- Create a value of 'ArchiveRule' 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:
--
-- 'retainRule', 'archiveRule_retainRule' - Information about the retention period for the snapshot archiving rule.
newArchiveRule ::
  -- | 'retainRule'
  ArchiveRetainRule ->
  ArchiveRule
newArchiveRule :: ArchiveRetainRule -> ArchiveRule
newArchiveRule ArchiveRetainRule
pRetainRule_ =
  ArchiveRule' {$sel:retainRule:ArchiveRule' :: ArchiveRetainRule
retainRule = ArchiveRetainRule
pRetainRule_}

-- | Information about the retention period for the snapshot archiving rule.
archiveRule_retainRule :: Lens.Lens' ArchiveRule ArchiveRetainRule
archiveRule_retainRule :: Lens' ArchiveRule ArchiveRetainRule
archiveRule_retainRule = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ArchiveRule' {ArchiveRetainRule
retainRule :: ArchiveRetainRule
$sel:retainRule:ArchiveRule' :: ArchiveRule -> ArchiveRetainRule
retainRule} -> ArchiveRetainRule
retainRule) (\s :: ArchiveRule
s@ArchiveRule' {} ArchiveRetainRule
a -> ArchiveRule
s {$sel:retainRule:ArchiveRule' :: ArchiveRetainRule
retainRule = ArchiveRetainRule
a} :: ArchiveRule)

instance Data.FromJSON ArchiveRule where
  parseJSON :: Value -> Parser ArchiveRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ArchiveRule"
      ( \Object
x ->
          ArchiveRetainRule -> ArchiveRule
ArchiveRule' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"RetainRule")
      )

instance Prelude.Hashable ArchiveRule where
  hashWithSalt :: Int -> ArchiveRule -> Int
hashWithSalt Int
_salt ArchiveRule' {ArchiveRetainRule
retainRule :: ArchiveRetainRule
$sel:retainRule:ArchiveRule' :: ArchiveRule -> ArchiveRetainRule
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ArchiveRetainRule
retainRule

instance Prelude.NFData ArchiveRule where
  rnf :: ArchiveRule -> ()
rnf ArchiveRule' {ArchiveRetainRule
retainRule :: ArchiveRetainRule
$sel:retainRule:ArchiveRule' :: ArchiveRule -> ArchiveRetainRule
..} = forall a. NFData a => a -> ()
Prelude.rnf ArchiveRetainRule
retainRule

instance Data.ToJSON ArchiveRule where
  toJSON :: ArchiveRule -> Value
toJSON ArchiveRule' {ArchiveRetainRule
retainRule :: ArchiveRetainRule
$sel:retainRule:ArchiveRule' :: ArchiveRule -> ArchiveRetainRule
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"RetainRule" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ArchiveRetainRule
retainRule)]
      )