{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.BillingConductor.AssociateAccounts
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Connects an array of account IDs in a consolidated billing family to a
-- predefined billing group. The account IDs must be a part of the
-- consolidated billing family during the current month, and not already
-- associated with another billing group. The maximum number of accounts
-- that can be associated in one call is 30.
module Amazonka.BillingConductor.AssociateAccounts
  ( -- * Creating a Request
    AssociateAccounts (..),
    newAssociateAccounts,

    -- * Request Lenses
    associateAccounts_arn,
    associateAccounts_accountIds,

    -- * Destructuring the Response
    AssociateAccountsResponse (..),
    newAssociateAccountsResponse,

    -- * Response Lenses
    associateAccountsResponse_arn,
    associateAccountsResponse_httpStatus,
  )
where

import Amazonka.BillingConductor.Types
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociateAccounts' smart constructor.
data AssociateAccounts = AssociateAccounts'
  { -- | The Amazon Resource Name (ARN) of the billing group that associates the
    -- array of account IDs.
    AssociateAccounts -> Text
arn :: Prelude.Text,
    -- | The associating array of account IDs.
    AssociateAccounts -> NonEmpty Text
accountIds :: Prelude.NonEmpty Prelude.Text
  }
  deriving (AssociateAccounts -> AssociateAccounts -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateAccounts -> AssociateAccounts -> Bool
$c/= :: AssociateAccounts -> AssociateAccounts -> Bool
== :: AssociateAccounts -> AssociateAccounts -> Bool
$c== :: AssociateAccounts -> AssociateAccounts -> Bool
Prelude.Eq, ReadPrec [AssociateAccounts]
ReadPrec AssociateAccounts
Int -> ReadS AssociateAccounts
ReadS [AssociateAccounts]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateAccounts]
$creadListPrec :: ReadPrec [AssociateAccounts]
readPrec :: ReadPrec AssociateAccounts
$creadPrec :: ReadPrec AssociateAccounts
readList :: ReadS [AssociateAccounts]
$creadList :: ReadS [AssociateAccounts]
readsPrec :: Int -> ReadS AssociateAccounts
$creadsPrec :: Int -> ReadS AssociateAccounts
Prelude.Read, Int -> AssociateAccounts -> ShowS
[AssociateAccounts] -> ShowS
AssociateAccounts -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateAccounts] -> ShowS
$cshowList :: [AssociateAccounts] -> ShowS
show :: AssociateAccounts -> String
$cshow :: AssociateAccounts -> String
showsPrec :: Int -> AssociateAccounts -> ShowS
$cshowsPrec :: Int -> AssociateAccounts -> ShowS
Prelude.Show, forall x. Rep AssociateAccounts x -> AssociateAccounts
forall x. AssociateAccounts -> Rep AssociateAccounts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateAccounts x -> AssociateAccounts
$cfrom :: forall x. AssociateAccounts -> Rep AssociateAccounts x
Prelude.Generic)

-- |
-- Create a value of 'AssociateAccounts' 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:
--
-- 'arn', 'associateAccounts_arn' - The Amazon Resource Name (ARN) of the billing group that associates the
-- array of account IDs.
--
-- 'accountIds', 'associateAccounts_accountIds' - The associating array of account IDs.
newAssociateAccounts ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'accountIds'
  Prelude.NonEmpty Prelude.Text ->
  AssociateAccounts
newAssociateAccounts :: Text -> NonEmpty Text -> AssociateAccounts
newAssociateAccounts Text
pArn_ NonEmpty Text
pAccountIds_ =
  AssociateAccounts'
    { $sel:arn:AssociateAccounts' :: Text
arn = Text
pArn_,
      $sel:accountIds:AssociateAccounts' :: 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_
    }

-- | The Amazon Resource Name (ARN) of the billing group that associates the
-- array of account IDs.
associateAccounts_arn :: Lens.Lens' AssociateAccounts Prelude.Text
associateAccounts_arn :: Lens' AssociateAccounts Text
associateAccounts_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAccounts' {Text
arn :: Text
$sel:arn:AssociateAccounts' :: AssociateAccounts -> Text
arn} -> Text
arn) (\s :: AssociateAccounts
s@AssociateAccounts' {} Text
a -> AssociateAccounts
s {$sel:arn:AssociateAccounts' :: Text
arn = Text
a} :: AssociateAccounts)

-- | The associating array of account IDs.
associateAccounts_accountIds :: Lens.Lens' AssociateAccounts (Prelude.NonEmpty Prelude.Text)
associateAccounts_accountIds :: Lens' AssociateAccounts (NonEmpty Text)
associateAccounts_accountIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAccounts' {NonEmpty Text
accountIds :: NonEmpty Text
$sel:accountIds:AssociateAccounts' :: AssociateAccounts -> NonEmpty Text
accountIds} -> NonEmpty Text
accountIds) (\s :: AssociateAccounts
s@AssociateAccounts' {} NonEmpty Text
a -> AssociateAccounts
s {$sel:accountIds:AssociateAccounts' :: NonEmpty Text
accountIds = NonEmpty Text
a} :: AssociateAccounts) 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 Core.AWSRequest AssociateAccounts where
  type
    AWSResponse AssociateAccounts =
      AssociateAccountsResponse
  request :: (Service -> Service)
-> AssociateAccounts -> Request AssociateAccounts
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateAccounts
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateAccounts)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> AssociateAccountsResponse
AssociateAccountsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Arn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AssociateAccounts where
  hashWithSalt :: Int -> AssociateAccounts -> Int
hashWithSalt Int
_salt AssociateAccounts' {NonEmpty Text
Text
accountIds :: NonEmpty Text
arn :: Text
$sel:accountIds:AssociateAccounts' :: AssociateAccounts -> NonEmpty Text
$sel:arn:AssociateAccounts' :: AssociateAccounts -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
accountIds

instance Prelude.NFData AssociateAccounts where
  rnf :: AssociateAccounts -> ()
rnf AssociateAccounts' {NonEmpty Text
Text
accountIds :: NonEmpty Text
arn :: Text
$sel:accountIds:AssociateAccounts' :: AssociateAccounts -> NonEmpty Text
$sel:arn:AssociateAccounts' :: AssociateAccounts -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
accountIds

instance Data.ToHeaders AssociateAccounts where
  toHeaders :: AssociateAccounts -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON AssociateAccounts where
  toJSON :: AssociateAccounts -> Value
toJSON AssociateAccounts' {NonEmpty Text
Text
accountIds :: NonEmpty Text
arn :: Text
$sel:accountIds:AssociateAccounts' :: AssociateAccounts -> NonEmpty Text
$sel:arn:AssociateAccounts' :: AssociateAccounts -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Arn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
arn),
            forall a. a -> Maybe a
Prelude.Just (Key
"AccountIds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
accountIds)
          ]
      )

instance Data.ToPath AssociateAccounts where
  toPath :: AssociateAccounts -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/associate-accounts"

instance Data.ToQuery AssociateAccounts where
  toQuery :: AssociateAccounts -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newAssociateAccountsResponse' smart constructor.
data AssociateAccountsResponse = AssociateAccountsResponse'
  { -- | The Amazon Resource Name (ARN) of the billing group that associates the
    -- array of account IDs.
    AssociateAccountsResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    AssociateAccountsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AssociateAccountsResponse -> AssociateAccountsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateAccountsResponse -> AssociateAccountsResponse -> Bool
$c/= :: AssociateAccountsResponse -> AssociateAccountsResponse -> Bool
== :: AssociateAccountsResponse -> AssociateAccountsResponse -> Bool
$c== :: AssociateAccountsResponse -> AssociateAccountsResponse -> Bool
Prelude.Eq, ReadPrec [AssociateAccountsResponse]
ReadPrec AssociateAccountsResponse
Int -> ReadS AssociateAccountsResponse
ReadS [AssociateAccountsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateAccountsResponse]
$creadListPrec :: ReadPrec [AssociateAccountsResponse]
readPrec :: ReadPrec AssociateAccountsResponse
$creadPrec :: ReadPrec AssociateAccountsResponse
readList :: ReadS [AssociateAccountsResponse]
$creadList :: ReadS [AssociateAccountsResponse]
readsPrec :: Int -> ReadS AssociateAccountsResponse
$creadsPrec :: Int -> ReadS AssociateAccountsResponse
Prelude.Read, Int -> AssociateAccountsResponse -> ShowS
[AssociateAccountsResponse] -> ShowS
AssociateAccountsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateAccountsResponse] -> ShowS
$cshowList :: [AssociateAccountsResponse] -> ShowS
show :: AssociateAccountsResponse -> String
$cshow :: AssociateAccountsResponse -> String
showsPrec :: Int -> AssociateAccountsResponse -> ShowS
$cshowsPrec :: Int -> AssociateAccountsResponse -> ShowS
Prelude.Show, forall x.
Rep AssociateAccountsResponse x -> AssociateAccountsResponse
forall x.
AssociateAccountsResponse -> Rep AssociateAccountsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateAccountsResponse x -> AssociateAccountsResponse
$cfrom :: forall x.
AssociateAccountsResponse -> Rep AssociateAccountsResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateAccountsResponse' 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:
--
-- 'arn', 'associateAccountsResponse_arn' - The Amazon Resource Name (ARN) of the billing group that associates the
-- array of account IDs.
--
-- 'httpStatus', 'associateAccountsResponse_httpStatus' - The response's http status code.
newAssociateAccountsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateAccountsResponse
newAssociateAccountsResponse :: Int -> AssociateAccountsResponse
newAssociateAccountsResponse Int
pHttpStatus_ =
  AssociateAccountsResponse'
    { $sel:arn:AssociateAccountsResponse' :: Maybe Text
arn = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociateAccountsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the billing group that associates the
-- array of account IDs.
associateAccountsResponse_arn :: Lens.Lens' AssociateAccountsResponse (Prelude.Maybe Prelude.Text)
associateAccountsResponse_arn :: Lens' AssociateAccountsResponse (Maybe Text)
associateAccountsResponse_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAccountsResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:AssociateAccountsResponse' :: AssociateAccountsResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: AssociateAccountsResponse
s@AssociateAccountsResponse' {} Maybe Text
a -> AssociateAccountsResponse
s {$sel:arn:AssociateAccountsResponse' :: Maybe Text
arn = Maybe Text
a} :: AssociateAccountsResponse)

-- | The response's http status code.
associateAccountsResponse_httpStatus :: Lens.Lens' AssociateAccountsResponse Prelude.Int
associateAccountsResponse_httpStatus :: Lens' AssociateAccountsResponse Int
associateAccountsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAccountsResponse' {Int
httpStatus :: Int
$sel:httpStatus:AssociateAccountsResponse' :: AssociateAccountsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AssociateAccountsResponse
s@AssociateAccountsResponse' {} Int
a -> AssociateAccountsResponse
s {$sel:httpStatus:AssociateAccountsResponse' :: Int
httpStatus = Int
a} :: AssociateAccountsResponse)

instance Prelude.NFData AssociateAccountsResponse where
  rnf :: AssociateAccountsResponse -> ()
rnf AssociateAccountsResponse' {Int
Maybe Text
httpStatus :: Int
arn :: Maybe Text
$sel:httpStatus:AssociateAccountsResponse' :: AssociateAccountsResponse -> Int
$sel:arn:AssociateAccountsResponse' :: AssociateAccountsResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus