{-# 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.Config.Types.OrganizationAggregationSource
-- 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.Config.Types.OrganizationAggregationSource 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

-- | This object contains regions to set up the aggregator and an IAM role to
-- retrieve organization details.
--
-- /See:/ 'newOrganizationAggregationSource' smart constructor.
data OrganizationAggregationSource = OrganizationAggregationSource'
  { -- | If true, aggregate existing Config regions and future regions.
    OrganizationAggregationSource -> Maybe Bool
allAwsRegions :: Prelude.Maybe Prelude.Bool,
    -- | The source regions being aggregated.
    OrganizationAggregationSource -> Maybe (NonEmpty Text)
awsRegions :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | ARN of the IAM role used to retrieve Amazon Web Services Organization
    -- details associated with the aggregator account.
    OrganizationAggregationSource -> Text
roleArn :: Prelude.Text
  }
  deriving (OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
$c/= :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
== :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
$c== :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
Prelude.Eq, ReadPrec [OrganizationAggregationSource]
ReadPrec OrganizationAggregationSource
Int -> ReadS OrganizationAggregationSource
ReadS [OrganizationAggregationSource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OrganizationAggregationSource]
$creadListPrec :: ReadPrec [OrganizationAggregationSource]
readPrec :: ReadPrec OrganizationAggregationSource
$creadPrec :: ReadPrec OrganizationAggregationSource
readList :: ReadS [OrganizationAggregationSource]
$creadList :: ReadS [OrganizationAggregationSource]
readsPrec :: Int -> ReadS OrganizationAggregationSource
$creadsPrec :: Int -> ReadS OrganizationAggregationSource
Prelude.Read, Int -> OrganizationAggregationSource -> ShowS
[OrganizationAggregationSource] -> ShowS
OrganizationAggregationSource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrganizationAggregationSource] -> ShowS
$cshowList :: [OrganizationAggregationSource] -> ShowS
show :: OrganizationAggregationSource -> String
$cshow :: OrganizationAggregationSource -> String
showsPrec :: Int -> OrganizationAggregationSource -> ShowS
$cshowsPrec :: Int -> OrganizationAggregationSource -> ShowS
Prelude.Show, forall x.
Rep OrganizationAggregationSource x
-> OrganizationAggregationSource
forall x.
OrganizationAggregationSource
-> Rep OrganizationAggregationSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep OrganizationAggregationSource x
-> OrganizationAggregationSource
$cfrom :: forall x.
OrganizationAggregationSource
-> Rep OrganizationAggregationSource x
Prelude.Generic)

-- |
-- Create a value of 'OrganizationAggregationSource' 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:
--
-- 'allAwsRegions', 'organizationAggregationSource_allAwsRegions' - If true, aggregate existing Config regions and future regions.
--
-- 'awsRegions', 'organizationAggregationSource_awsRegions' - The source regions being aggregated.
--
-- 'roleArn', 'organizationAggregationSource_roleArn' - ARN of the IAM role used to retrieve Amazon Web Services Organization
-- details associated with the aggregator account.
newOrganizationAggregationSource ::
  -- | 'roleArn'
  Prelude.Text ->
  OrganizationAggregationSource
newOrganizationAggregationSource :: Text -> OrganizationAggregationSource
newOrganizationAggregationSource Text
pRoleArn_ =
  OrganizationAggregationSource'
    { $sel:allAwsRegions:OrganizationAggregationSource' :: Maybe Bool
allAwsRegions =
        forall a. Maybe a
Prelude.Nothing,
      $sel:awsRegions:OrganizationAggregationSource' :: Maybe (NonEmpty Text)
awsRegions = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:OrganizationAggregationSource' :: Text
roleArn = Text
pRoleArn_
    }

-- | If true, aggregate existing Config regions and future regions.
organizationAggregationSource_allAwsRegions :: Lens.Lens' OrganizationAggregationSource (Prelude.Maybe Prelude.Bool)
organizationAggregationSource_allAwsRegions :: Lens' OrganizationAggregationSource (Maybe Bool)
organizationAggregationSource_allAwsRegions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrganizationAggregationSource' {Maybe Bool
allAwsRegions :: Maybe Bool
$sel:allAwsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe Bool
allAwsRegions} -> Maybe Bool
allAwsRegions) (\s :: OrganizationAggregationSource
s@OrganizationAggregationSource' {} Maybe Bool
a -> OrganizationAggregationSource
s {$sel:allAwsRegions:OrganizationAggregationSource' :: Maybe Bool
allAwsRegions = Maybe Bool
a} :: OrganizationAggregationSource)

-- | The source regions being aggregated.
organizationAggregationSource_awsRegions :: Lens.Lens' OrganizationAggregationSource (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
organizationAggregationSource_awsRegions :: Lens' OrganizationAggregationSource (Maybe (NonEmpty Text))
organizationAggregationSource_awsRegions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrganizationAggregationSource' {Maybe (NonEmpty Text)
awsRegions :: Maybe (NonEmpty Text)
$sel:awsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe (NonEmpty Text)
awsRegions} -> Maybe (NonEmpty Text)
awsRegions) (\s :: OrganizationAggregationSource
s@OrganizationAggregationSource' {} Maybe (NonEmpty Text)
a -> OrganizationAggregationSource
s {$sel:awsRegions:OrganizationAggregationSource' :: Maybe (NonEmpty Text)
awsRegions = Maybe (NonEmpty Text)
a} :: OrganizationAggregationSource) 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

-- | ARN of the IAM role used to retrieve Amazon Web Services Organization
-- details associated with the aggregator account.
organizationAggregationSource_roleArn :: Lens.Lens' OrganizationAggregationSource Prelude.Text
organizationAggregationSource_roleArn :: Lens' OrganizationAggregationSource Text
organizationAggregationSource_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrganizationAggregationSource' {Text
roleArn :: Text
$sel:roleArn:OrganizationAggregationSource' :: OrganizationAggregationSource -> Text
roleArn} -> Text
roleArn) (\s :: OrganizationAggregationSource
s@OrganizationAggregationSource' {} Text
a -> OrganizationAggregationSource
s {$sel:roleArn:OrganizationAggregationSource' :: Text
roleArn = Text
a} :: OrganizationAggregationSource)

instance Data.FromJSON OrganizationAggregationSource where
  parseJSON :: Value -> Parser OrganizationAggregationSource
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"OrganizationAggregationSource"
      ( \Object
x ->
          Maybe Bool
-> Maybe (NonEmpty Text) -> Text -> OrganizationAggregationSource
OrganizationAggregationSource'
            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
"AllAwsRegions")
            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
"AwsRegions")
            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
"RoleArn")
      )

instance
  Prelude.Hashable
    OrganizationAggregationSource
  where
  hashWithSalt :: Int -> OrganizationAggregationSource -> Int
hashWithSalt Int
_salt OrganizationAggregationSource' {Maybe Bool
Maybe (NonEmpty Text)
Text
roleArn :: Text
awsRegions :: Maybe (NonEmpty Text)
allAwsRegions :: Maybe Bool
$sel:roleArn:OrganizationAggregationSource' :: OrganizationAggregationSource -> Text
$sel:awsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe (NonEmpty Text)
$sel:allAwsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
allAwsRegions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
awsRegions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn

instance Prelude.NFData OrganizationAggregationSource where
  rnf :: OrganizationAggregationSource -> ()
rnf OrganizationAggregationSource' {Maybe Bool
Maybe (NonEmpty Text)
Text
roleArn :: Text
awsRegions :: Maybe (NonEmpty Text)
allAwsRegions :: Maybe Bool
$sel:roleArn:OrganizationAggregationSource' :: OrganizationAggregationSource -> Text
$sel:awsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe (NonEmpty Text)
$sel:allAwsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
allAwsRegions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
awsRegions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn

instance Data.ToJSON OrganizationAggregationSource where
  toJSON :: OrganizationAggregationSource -> Value
toJSON OrganizationAggregationSource' {Maybe Bool
Maybe (NonEmpty Text)
Text
roleArn :: Text
awsRegions :: Maybe (NonEmpty Text)
allAwsRegions :: Maybe Bool
$sel:roleArn:OrganizationAggregationSource' :: OrganizationAggregationSource -> Text
$sel:awsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe (NonEmpty Text)
$sel:allAwsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AllAwsRegions" 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 Bool
allAwsRegions,
            (Key
"AwsRegions" 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 (NonEmpty Text)
awsRegions,
            forall a. a -> Maybe a
Prelude.Just (Key
"RoleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleArn)
          ]
      )