{-# 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.AccountAggregationSource
-- 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.AccountAggregationSource 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

-- | A collection of accounts and regions.
--
-- /See:/ 'newAccountAggregationSource' smart constructor.
data AccountAggregationSource = AccountAggregationSource'
  { -- | If true, aggregate existing Config regions and future regions.
    AccountAggregationSource -> Maybe Bool
allAwsRegions :: Prelude.Maybe Prelude.Bool,
    -- | The source regions being aggregated.
    AccountAggregationSource -> Maybe (NonEmpty Text)
awsRegions :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The 12-digit account ID of the account being aggregated.
    AccountAggregationSource -> NonEmpty Text
accountIds :: Prelude.NonEmpty Prelude.Text
  }
  deriving (AccountAggregationSource -> AccountAggregationSource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccountAggregationSource -> AccountAggregationSource -> Bool
$c/= :: AccountAggregationSource -> AccountAggregationSource -> Bool
== :: AccountAggregationSource -> AccountAggregationSource -> Bool
$c== :: AccountAggregationSource -> AccountAggregationSource -> Bool
Prelude.Eq, ReadPrec [AccountAggregationSource]
ReadPrec AccountAggregationSource
Int -> ReadS AccountAggregationSource
ReadS [AccountAggregationSource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccountAggregationSource]
$creadListPrec :: ReadPrec [AccountAggregationSource]
readPrec :: ReadPrec AccountAggregationSource
$creadPrec :: ReadPrec AccountAggregationSource
readList :: ReadS [AccountAggregationSource]
$creadList :: ReadS [AccountAggregationSource]
readsPrec :: Int -> ReadS AccountAggregationSource
$creadsPrec :: Int -> ReadS AccountAggregationSource
Prelude.Read, Int -> AccountAggregationSource -> ShowS
[AccountAggregationSource] -> ShowS
AccountAggregationSource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccountAggregationSource] -> ShowS
$cshowList :: [AccountAggregationSource] -> ShowS
show :: AccountAggregationSource -> String
$cshow :: AccountAggregationSource -> String
showsPrec :: Int -> AccountAggregationSource -> ShowS
$cshowsPrec :: Int -> AccountAggregationSource -> ShowS
Prelude.Show, forall x.
Rep AccountAggregationSource x -> AccountAggregationSource
forall x.
AccountAggregationSource -> Rep AccountAggregationSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AccountAggregationSource x -> AccountAggregationSource
$cfrom :: forall x.
AccountAggregationSource -> Rep AccountAggregationSource x
Prelude.Generic)

-- |
-- Create a value of 'AccountAggregationSource' 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', 'accountAggregationSource_allAwsRegions' - If true, aggregate existing Config regions and future regions.
--
-- 'awsRegions', 'accountAggregationSource_awsRegions' - The source regions being aggregated.
--
-- 'accountIds', 'accountAggregationSource_accountIds' - The 12-digit account ID of the account being aggregated.
newAccountAggregationSource ::
  -- | 'accountIds'
  Prelude.NonEmpty Prelude.Text ->
  AccountAggregationSource
newAccountAggregationSource :: NonEmpty Text -> AccountAggregationSource
newAccountAggregationSource NonEmpty Text
pAccountIds_ =
  AccountAggregationSource'
    { $sel:allAwsRegions:AccountAggregationSource' :: Maybe Bool
allAwsRegions =
        forall a. Maybe a
Prelude.Nothing,
      $sel:awsRegions:AccountAggregationSource' :: Maybe (NonEmpty Text)
awsRegions = forall a. Maybe a
Prelude.Nothing,
      $sel:accountIds:AccountAggregationSource' :: NonEmpty Text
accountIds = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pAccountIds_
    }

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

-- | The source regions being aggregated.
accountAggregationSource_awsRegions :: Lens.Lens' AccountAggregationSource (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
accountAggregationSource_awsRegions :: Lens' AccountAggregationSource (Maybe (NonEmpty Text))
accountAggregationSource_awsRegions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccountAggregationSource' {Maybe (NonEmpty Text)
awsRegions :: Maybe (NonEmpty Text)
$sel:awsRegions:AccountAggregationSource' :: AccountAggregationSource -> Maybe (NonEmpty Text)
awsRegions} -> Maybe (NonEmpty Text)
awsRegions) (\s :: AccountAggregationSource
s@AccountAggregationSource' {} Maybe (NonEmpty Text)
a -> AccountAggregationSource
s {$sel:awsRegions:AccountAggregationSource' :: Maybe (NonEmpty Text)
awsRegions = Maybe (NonEmpty Text)
a} :: AccountAggregationSource) 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 12-digit account ID of the account being aggregated.
accountAggregationSource_accountIds :: Lens.Lens' AccountAggregationSource (Prelude.NonEmpty Prelude.Text)
accountAggregationSource_accountIds :: Lens' AccountAggregationSource (NonEmpty Text)
accountAggregationSource_accountIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccountAggregationSource' {NonEmpty Text
accountIds :: NonEmpty Text
$sel:accountIds:AccountAggregationSource' :: AccountAggregationSource -> NonEmpty Text
accountIds} -> NonEmpty Text
accountIds) (\s :: AccountAggregationSource
s@AccountAggregationSource' {} NonEmpty Text
a -> AccountAggregationSource
s {$sel:accountIds:AccountAggregationSource' :: NonEmpty Text
accountIds = NonEmpty Text
a} :: AccountAggregationSource) 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 AccountAggregationSource where
  parseJSON :: Value -> Parser AccountAggregationSource
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AccountAggregationSource"
      ( \Object
x ->
          Maybe Bool
-> Maybe (NonEmpty Text)
-> NonEmpty Text
-> AccountAggregationSource
AccountAggregationSource'
            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
"AccountIds")
      )

instance Prelude.Hashable AccountAggregationSource where
  hashWithSalt :: Int -> AccountAggregationSource -> Int
hashWithSalt Int
_salt AccountAggregationSource' {Maybe Bool
Maybe (NonEmpty Text)
NonEmpty Text
accountIds :: NonEmpty Text
awsRegions :: Maybe (NonEmpty Text)
allAwsRegions :: Maybe Bool
$sel:accountIds:AccountAggregationSource' :: AccountAggregationSource -> NonEmpty Text
$sel:awsRegions:AccountAggregationSource' :: AccountAggregationSource -> Maybe (NonEmpty Text)
$sel:allAwsRegions:AccountAggregationSource' :: AccountAggregationSource -> 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` NonEmpty Text
accountIds

instance Prelude.NFData AccountAggregationSource where
  rnf :: AccountAggregationSource -> ()
rnf AccountAggregationSource' {Maybe Bool
Maybe (NonEmpty Text)
NonEmpty Text
accountIds :: NonEmpty Text
awsRegions :: Maybe (NonEmpty Text)
allAwsRegions :: Maybe Bool
$sel:accountIds:AccountAggregationSource' :: AccountAggregationSource -> NonEmpty Text
$sel:awsRegions:AccountAggregationSource' :: AccountAggregationSource -> Maybe (NonEmpty Text)
$sel:allAwsRegions:AccountAggregationSource' :: AccountAggregationSource -> 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 NonEmpty Text
accountIds

instance Data.ToJSON AccountAggregationSource where
  toJSON :: AccountAggregationSource -> Value
toJSON AccountAggregationSource' {Maybe Bool
Maybe (NonEmpty Text)
NonEmpty Text
accountIds :: NonEmpty Text
awsRegions :: Maybe (NonEmpty Text)
allAwsRegions :: Maybe Bool
$sel:accountIds:AccountAggregationSource' :: AccountAggregationSource -> NonEmpty Text
$sel:awsRegions:AccountAggregationSource' :: AccountAggregationSource -> Maybe (NonEmpty Text)
$sel:allAwsRegions:AccountAggregationSource' :: AccountAggregationSource -> 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
"AccountIds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
accountIds)
          ]
      )