{-# 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.ControlScope
-- 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.ControlScope where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A framework consists of one or more controls. Each control has its own
-- control scope. The control scope defines what the control will evaluate.
-- Three examples of control scopes are: a specific backup plan, all backup
-- plans with a specific tag, or all backup plans.
--
-- To set a control scope that includes all of a particular resource, leave
-- the @ControlScope@ empty or do not pass it when calling
-- @CreateFramework@.
--
-- /See:/ 'newControlScope' smart constructor.
data ControlScope = ControlScope'
  { -- | Describes whether the control scope includes one or more types of
    -- resources, such as @EFS@ or @RDS@.
    ControlScope -> Maybe [Text]
complianceResourceTypes :: Prelude.Maybe [Prelude.Text],
    -- | Describes whether the control scope includes resources with one or more
    -- tags. Each tag is a key-value pair.
    ControlScope -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The ID of the only Amazon Web Services resource that you want your
    -- control scope to contain.
    ControlScope -> Maybe (NonEmpty Text)
complianceResourceIds :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (ControlScope -> ControlScope -> Bool
(ControlScope -> ControlScope -> Bool)
-> (ControlScope -> ControlScope -> Bool) -> Eq ControlScope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ControlScope -> ControlScope -> Bool
$c/= :: ControlScope -> ControlScope -> Bool
== :: ControlScope -> ControlScope -> Bool
$c== :: ControlScope -> ControlScope -> Bool
Prelude.Eq, ReadPrec [ControlScope]
ReadPrec ControlScope
Int -> ReadS ControlScope
ReadS [ControlScope]
(Int -> ReadS ControlScope)
-> ReadS [ControlScope]
-> ReadPrec ControlScope
-> ReadPrec [ControlScope]
-> Read ControlScope
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ControlScope]
$creadListPrec :: ReadPrec [ControlScope]
readPrec :: ReadPrec ControlScope
$creadPrec :: ReadPrec ControlScope
readList :: ReadS [ControlScope]
$creadList :: ReadS [ControlScope]
readsPrec :: Int -> ReadS ControlScope
$creadsPrec :: Int -> ReadS ControlScope
Prelude.Read, Int -> ControlScope -> ShowS
[ControlScope] -> ShowS
ControlScope -> String
(Int -> ControlScope -> ShowS)
-> (ControlScope -> String)
-> ([ControlScope] -> ShowS)
-> Show ControlScope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ControlScope] -> ShowS
$cshowList :: [ControlScope] -> ShowS
show :: ControlScope -> String
$cshow :: ControlScope -> String
showsPrec :: Int -> ControlScope -> ShowS
$cshowsPrec :: Int -> ControlScope -> ShowS
Prelude.Show, (forall x. ControlScope -> Rep ControlScope x)
-> (forall x. Rep ControlScope x -> ControlScope)
-> Generic ControlScope
forall x. Rep ControlScope x -> ControlScope
forall x. ControlScope -> Rep ControlScope x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ControlScope x -> ControlScope
$cfrom :: forall x. ControlScope -> Rep ControlScope x
Prelude.Generic)

-- |
-- Create a value of 'ControlScope' 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:
--
-- 'complianceResourceTypes', 'controlScope_complianceResourceTypes' - Describes whether the control scope includes one or more types of
-- resources, such as @EFS@ or @RDS@.
--
-- 'tags', 'controlScope_tags' - Describes whether the control scope includes resources with one or more
-- tags. Each tag is a key-value pair.
--
-- 'complianceResourceIds', 'controlScope_complianceResourceIds' - The ID of the only Amazon Web Services resource that you want your
-- control scope to contain.
newControlScope ::
  ControlScope
newControlScope :: ControlScope
newControlScope =
  ControlScope' :: Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe (NonEmpty Text)
-> ControlScope
ControlScope'
    { $sel:complianceResourceTypes:ControlScope' :: Maybe [Text]
complianceResourceTypes =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:ControlScope' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:complianceResourceIds:ControlScope' :: Maybe (NonEmpty Text)
complianceResourceIds = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | Describes whether the control scope includes one or more types of
-- resources, such as @EFS@ or @RDS@.
controlScope_complianceResourceTypes :: Lens.Lens' ControlScope (Prelude.Maybe [Prelude.Text])
controlScope_complianceResourceTypes :: (Maybe [Text] -> f (Maybe [Text]))
-> ControlScope -> f ControlScope
controlScope_complianceResourceTypes = (ControlScope -> Maybe [Text])
-> (ControlScope -> Maybe [Text] -> ControlScope)
-> Lens ControlScope ControlScope (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ControlScope' {Maybe [Text]
complianceResourceTypes :: Maybe [Text]
$sel:complianceResourceTypes:ControlScope' :: ControlScope -> Maybe [Text]
complianceResourceTypes} -> Maybe [Text]
complianceResourceTypes) (\s :: ControlScope
s@ControlScope' {} Maybe [Text]
a -> ControlScope
s {$sel:complianceResourceTypes:ControlScope' :: Maybe [Text]
complianceResourceTypes = Maybe [Text]
a} :: ControlScope) ((Maybe [Text] -> f (Maybe [Text]))
 -> ControlScope -> f ControlScope)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> ControlScope
-> f ControlScope
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Describes whether the control scope includes resources with one or more
-- tags. Each tag is a key-value pair.
controlScope_tags :: Lens.Lens' ControlScope (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
controlScope_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> ControlScope -> f ControlScope
controlScope_tags = (ControlScope -> Maybe (HashMap Text Text))
-> (ControlScope -> Maybe (HashMap Text Text) -> ControlScope)
-> Lens
     ControlScope
     ControlScope
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ControlScope' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:ControlScope' :: ControlScope -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: ControlScope
s@ControlScope' {} Maybe (HashMap Text Text)
a -> ControlScope
s {$sel:tags:ControlScope' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: ControlScope) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> ControlScope -> f ControlScope)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> ControlScope
-> f ControlScope
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the only Amazon Web Services resource that you want your
-- control scope to contain.
controlScope_complianceResourceIds :: Lens.Lens' ControlScope (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
controlScope_complianceResourceIds :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ControlScope -> f ControlScope
controlScope_complianceResourceIds = (ControlScope -> Maybe (NonEmpty Text))
-> (ControlScope -> Maybe (NonEmpty Text) -> ControlScope)
-> Lens
     ControlScope
     ControlScope
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ControlScope' {Maybe (NonEmpty Text)
complianceResourceIds :: Maybe (NonEmpty Text)
$sel:complianceResourceIds:ControlScope' :: ControlScope -> Maybe (NonEmpty Text)
complianceResourceIds} -> Maybe (NonEmpty Text)
complianceResourceIds) (\s :: ControlScope
s@ControlScope' {} Maybe (NonEmpty Text)
a -> ControlScope
s {$sel:complianceResourceIds:ControlScope' :: Maybe (NonEmpty Text)
complianceResourceIds = Maybe (NonEmpty Text)
a} :: ControlScope) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> ControlScope -> f ControlScope)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ControlScope
-> f ControlScope
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON ControlScope where
  parseJSON :: Value -> Parser ControlScope
parseJSON =
    String
-> (Object -> Parser ControlScope) -> Value -> Parser ControlScope
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ControlScope"
      ( \Object
x ->
          Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe (NonEmpty Text)
-> ControlScope
ControlScope'
            (Maybe [Text]
 -> Maybe (HashMap Text Text)
 -> Maybe (NonEmpty Text)
 -> ControlScope)
-> Parser (Maybe [Text])
-> Parser
     (Maybe (HashMap Text Text)
      -> Maybe (NonEmpty Text) -> ControlScope)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ComplianceResourceTypes"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser
  (Maybe (HashMap Text Text)
   -> Maybe (NonEmpty Text) -> ControlScope)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Maybe (NonEmpty Text) -> ControlScope)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Tags" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe (NonEmpty Text) -> ControlScope)
-> Parser (Maybe (NonEmpty Text)) -> Parser ControlScope
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ComplianceResourceIds")
      )

instance Prelude.Hashable ControlScope

instance Prelude.NFData ControlScope

instance Core.ToJSON ControlScope where
  toJSON :: ControlScope -> Value
toJSON ControlScope' {Maybe [Text]
Maybe (NonEmpty Text)
Maybe (HashMap Text Text)
complianceResourceIds :: Maybe (NonEmpty Text)
tags :: Maybe (HashMap Text Text)
complianceResourceTypes :: Maybe [Text]
$sel:complianceResourceIds:ControlScope' :: ControlScope -> Maybe (NonEmpty Text)
$sel:tags:ControlScope' :: ControlScope -> Maybe (HashMap Text Text)
$sel:complianceResourceTypes:ControlScope' :: ControlScope -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ComplianceResourceTypes" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
complianceResourceTypes,
            (Text
"Tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags,
            (Text
"ComplianceResourceIds" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
complianceResourceIds
          ]
      )