{-# 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.Account.GetAlternateContact
-- 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)
--
-- Retrieves the specified alternate contact attached to an Amazon Web
-- Services account.
--
-- For complete details about how to use the alternate contact operations,
-- see
-- <https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-update-contact.html Access or updating the alternate contacts>.
module Amazonka.Account.GetAlternateContact
  ( -- * Creating a Request
    GetAlternateContact (..),
    newGetAlternateContact,

    -- * Request Lenses
    getAlternateContact_accountId,
    getAlternateContact_alternateContactType,

    -- * Destructuring the Response
    GetAlternateContactResponse (..),
    newGetAlternateContactResponse,

    -- * Response Lenses
    getAlternateContactResponse_alternateContact,
    getAlternateContactResponse_httpStatus,
  )
where

import Amazonka.Account.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetAlternateContact' smart constructor.
data GetAlternateContact = GetAlternateContact'
  { -- | Specifies the 12 digit account ID number of the Amazon Web Services
    -- account that you want to access or modify with this operation.
    --
    -- If you do not specify this parameter, it defaults to the Amazon Web
    -- Services account of the identity used to call the operation.
    --
    -- To use this parameter, the caller must be an identity in the
    -- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#account organization\'s management account>
    -- or a delegated administrator account, and the specified account ID must
    -- be a member account in the same organization. The organization must have
    -- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_support-all-features.html all features enabled>,
    -- and the organization must have
    -- <https://docs.aws.amazon.com/organizations/latest/userguide/using-orgs-trusted-access.html trusted access>
    -- enabled for the Account Management service, and optionally a
    -- <https://docs.aws.amazon.com/organizations/latest/userguide/using-orgs-delegated-admin.html delegated admin>
    -- account assigned.
    --
    -- The management account can\'t specify its own @AccountId@; it must call
    -- the operation in standalone context by not including the @AccountId@
    -- parameter.
    --
    -- To call this operation on an account that is not a member of an
    -- organization, then don\'t specify this parameter, and call the operation
    -- using an identity belonging to the account whose contacts you wish to
    -- retrieve or modify.
    GetAlternateContact -> Maybe Text
accountId :: Prelude.Maybe Prelude.Text,
    -- | Specifies which alternate contact you want to retrieve.
    GetAlternateContact -> AlternateContactType
alternateContactType :: AlternateContactType
  }
  deriving (GetAlternateContact -> GetAlternateContact -> Bool
(GetAlternateContact -> GetAlternateContact -> Bool)
-> (GetAlternateContact -> GetAlternateContact -> Bool)
-> Eq GetAlternateContact
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAlternateContact -> GetAlternateContact -> Bool
$c/= :: GetAlternateContact -> GetAlternateContact -> Bool
== :: GetAlternateContact -> GetAlternateContact -> Bool
$c== :: GetAlternateContact -> GetAlternateContact -> Bool
Prelude.Eq, ReadPrec [GetAlternateContact]
ReadPrec GetAlternateContact
Int -> ReadS GetAlternateContact
ReadS [GetAlternateContact]
(Int -> ReadS GetAlternateContact)
-> ReadS [GetAlternateContact]
-> ReadPrec GetAlternateContact
-> ReadPrec [GetAlternateContact]
-> Read GetAlternateContact
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAlternateContact]
$creadListPrec :: ReadPrec [GetAlternateContact]
readPrec :: ReadPrec GetAlternateContact
$creadPrec :: ReadPrec GetAlternateContact
readList :: ReadS [GetAlternateContact]
$creadList :: ReadS [GetAlternateContact]
readsPrec :: Int -> ReadS GetAlternateContact
$creadsPrec :: Int -> ReadS GetAlternateContact
Prelude.Read, Int -> GetAlternateContact -> ShowS
[GetAlternateContact] -> ShowS
GetAlternateContact -> String
(Int -> GetAlternateContact -> ShowS)
-> (GetAlternateContact -> String)
-> ([GetAlternateContact] -> ShowS)
-> Show GetAlternateContact
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAlternateContact] -> ShowS
$cshowList :: [GetAlternateContact] -> ShowS
show :: GetAlternateContact -> String
$cshow :: GetAlternateContact -> String
showsPrec :: Int -> GetAlternateContact -> ShowS
$cshowsPrec :: Int -> GetAlternateContact -> ShowS
Prelude.Show, (forall x. GetAlternateContact -> Rep GetAlternateContact x)
-> (forall x. Rep GetAlternateContact x -> GetAlternateContact)
-> Generic GetAlternateContact
forall x. Rep GetAlternateContact x -> GetAlternateContact
forall x. GetAlternateContact -> Rep GetAlternateContact x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAlternateContact x -> GetAlternateContact
$cfrom :: forall x. GetAlternateContact -> Rep GetAlternateContact x
Prelude.Generic)

-- |
-- Create a value of 'GetAlternateContact' 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:
--
-- 'accountId', 'getAlternateContact_accountId' - Specifies the 12 digit account ID number of the Amazon Web Services
-- account that you want to access or modify with this operation.
--
-- If you do not specify this parameter, it defaults to the Amazon Web
-- Services account of the identity used to call the operation.
--
-- To use this parameter, the caller must be an identity in the
-- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#account organization\'s management account>
-- or a delegated administrator account, and the specified account ID must
-- be a member account in the same organization. The organization must have
-- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_support-all-features.html all features enabled>,
-- and the organization must have
-- <https://docs.aws.amazon.com/organizations/latest/userguide/using-orgs-trusted-access.html trusted access>
-- enabled for the Account Management service, and optionally a
-- <https://docs.aws.amazon.com/organizations/latest/userguide/using-orgs-delegated-admin.html delegated admin>
-- account assigned.
--
-- The management account can\'t specify its own @AccountId@; it must call
-- the operation in standalone context by not including the @AccountId@
-- parameter.
--
-- To call this operation on an account that is not a member of an
-- organization, then don\'t specify this parameter, and call the operation
-- using an identity belonging to the account whose contacts you wish to
-- retrieve or modify.
--
-- 'alternateContactType', 'getAlternateContact_alternateContactType' - Specifies which alternate contact you want to retrieve.
newGetAlternateContact ::
  -- | 'alternateContactType'
  AlternateContactType ->
  GetAlternateContact
newGetAlternateContact :: AlternateContactType -> GetAlternateContact
newGetAlternateContact AlternateContactType
pAlternateContactType_ =
  GetAlternateContact' :: Maybe Text -> AlternateContactType -> GetAlternateContact
GetAlternateContact'
    { $sel:accountId:GetAlternateContact' :: Maybe Text
accountId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:alternateContactType:GetAlternateContact' :: AlternateContactType
alternateContactType = AlternateContactType
pAlternateContactType_
    }

-- | Specifies the 12 digit account ID number of the Amazon Web Services
-- account that you want to access or modify with this operation.
--
-- If you do not specify this parameter, it defaults to the Amazon Web
-- Services account of the identity used to call the operation.
--
-- To use this parameter, the caller must be an identity in the
-- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#account organization\'s management account>
-- or a delegated administrator account, and the specified account ID must
-- be a member account in the same organization. The organization must have
-- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_support-all-features.html all features enabled>,
-- and the organization must have
-- <https://docs.aws.amazon.com/organizations/latest/userguide/using-orgs-trusted-access.html trusted access>
-- enabled for the Account Management service, and optionally a
-- <https://docs.aws.amazon.com/organizations/latest/userguide/using-orgs-delegated-admin.html delegated admin>
-- account assigned.
--
-- The management account can\'t specify its own @AccountId@; it must call
-- the operation in standalone context by not including the @AccountId@
-- parameter.
--
-- To call this operation on an account that is not a member of an
-- organization, then don\'t specify this parameter, and call the operation
-- using an identity belonging to the account whose contacts you wish to
-- retrieve or modify.
getAlternateContact_accountId :: Lens.Lens' GetAlternateContact (Prelude.Maybe Prelude.Text)
getAlternateContact_accountId :: (Maybe Text -> f (Maybe Text))
-> GetAlternateContact -> f GetAlternateContact
getAlternateContact_accountId = (GetAlternateContact -> Maybe Text)
-> (GetAlternateContact -> Maybe Text -> GetAlternateContact)
-> Lens
     GetAlternateContact GetAlternateContact (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAlternateContact' {Maybe Text
accountId :: Maybe Text
$sel:accountId:GetAlternateContact' :: GetAlternateContact -> Maybe Text
accountId} -> Maybe Text
accountId) (\s :: GetAlternateContact
s@GetAlternateContact' {} Maybe Text
a -> GetAlternateContact
s {$sel:accountId:GetAlternateContact' :: Maybe Text
accountId = Maybe Text
a} :: GetAlternateContact)

-- | Specifies which alternate contact you want to retrieve.
getAlternateContact_alternateContactType :: Lens.Lens' GetAlternateContact AlternateContactType
getAlternateContact_alternateContactType :: (AlternateContactType -> f AlternateContactType)
-> GetAlternateContact -> f GetAlternateContact
getAlternateContact_alternateContactType = (GetAlternateContact -> AlternateContactType)
-> (GetAlternateContact
    -> AlternateContactType -> GetAlternateContact)
-> Lens
     GetAlternateContact
     GetAlternateContact
     AlternateContactType
     AlternateContactType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAlternateContact' {AlternateContactType
alternateContactType :: AlternateContactType
$sel:alternateContactType:GetAlternateContact' :: GetAlternateContact -> AlternateContactType
alternateContactType} -> AlternateContactType
alternateContactType) (\s :: GetAlternateContact
s@GetAlternateContact' {} AlternateContactType
a -> GetAlternateContact
s {$sel:alternateContactType:GetAlternateContact' :: AlternateContactType
alternateContactType = AlternateContactType
a} :: GetAlternateContact)

instance Core.AWSRequest GetAlternateContact where
  type
    AWSResponse GetAlternateContact =
      GetAlternateContactResponse
  request :: GetAlternateContact -> Request GetAlternateContact
request = Service -> GetAlternateContact -> Request GetAlternateContact
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetAlternateContact
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetAlternateContact)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetAlternateContact))
-> Logger
-> Service
-> Proxy GetAlternateContact
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetAlternateContact)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe AlternateContact -> Int -> GetAlternateContactResponse
GetAlternateContactResponse'
            (Maybe AlternateContact -> Int -> GetAlternateContactResponse)
-> Either String (Maybe AlternateContact)
-> Either String (Int -> GetAlternateContactResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe AlternateContact)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"AlternateContact")
            Either String (Int -> GetAlternateContactResponse)
-> Either String Int -> Either String GetAlternateContactResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetAlternateContact

instance Prelude.NFData GetAlternateContact

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

instance Core.ToJSON GetAlternateContact where
  toJSON :: GetAlternateContact -> Value
toJSON GetAlternateContact' {Maybe Text
AlternateContactType
alternateContactType :: AlternateContactType
accountId :: Maybe Text
$sel:alternateContactType:GetAlternateContact' :: GetAlternateContact -> AlternateContactType
$sel:accountId:GetAlternateContact' :: GetAlternateContact -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AccountId" 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
accountId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"AlternateContactType"
                  Text -> AlternateContactType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AlternateContactType
alternateContactType
              )
          ]
      )

instance Core.ToPath GetAlternateContact where
  toPath :: GetAlternateContact -> ByteString
toPath = ByteString -> GetAlternateContact -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/getAlternateContact"

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

-- | /See:/ 'newGetAlternateContactResponse' smart constructor.
data GetAlternateContactResponse = GetAlternateContactResponse'
  { -- | A structure that contains the details for the specified alternate
    -- contact.
    GetAlternateContactResponse -> Maybe AlternateContact
alternateContact :: Prelude.Maybe AlternateContact,
    -- | The response's http status code.
    GetAlternateContactResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetAlternateContactResponse -> GetAlternateContactResponse -> Bool
(GetAlternateContactResponse
 -> GetAlternateContactResponse -> Bool)
-> (GetAlternateContactResponse
    -> GetAlternateContactResponse -> Bool)
-> Eq GetAlternateContactResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAlternateContactResponse -> GetAlternateContactResponse -> Bool
$c/= :: GetAlternateContactResponse -> GetAlternateContactResponse -> Bool
== :: GetAlternateContactResponse -> GetAlternateContactResponse -> Bool
$c== :: GetAlternateContactResponse -> GetAlternateContactResponse -> Bool
Prelude.Eq, Int -> GetAlternateContactResponse -> ShowS
[GetAlternateContactResponse] -> ShowS
GetAlternateContactResponse -> String
(Int -> GetAlternateContactResponse -> ShowS)
-> (GetAlternateContactResponse -> String)
-> ([GetAlternateContactResponse] -> ShowS)
-> Show GetAlternateContactResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAlternateContactResponse] -> ShowS
$cshowList :: [GetAlternateContactResponse] -> ShowS
show :: GetAlternateContactResponse -> String
$cshow :: GetAlternateContactResponse -> String
showsPrec :: Int -> GetAlternateContactResponse -> ShowS
$cshowsPrec :: Int -> GetAlternateContactResponse -> ShowS
Prelude.Show, (forall x.
 GetAlternateContactResponse -> Rep GetAlternateContactResponse x)
-> (forall x.
    Rep GetAlternateContactResponse x -> GetAlternateContactResponse)
-> Generic GetAlternateContactResponse
forall x.
Rep GetAlternateContactResponse x -> GetAlternateContactResponse
forall x.
GetAlternateContactResponse -> Rep GetAlternateContactResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetAlternateContactResponse x -> GetAlternateContactResponse
$cfrom :: forall x.
GetAlternateContactResponse -> Rep GetAlternateContactResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetAlternateContactResponse' 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:
--
-- 'alternateContact', 'getAlternateContactResponse_alternateContact' - A structure that contains the details for the specified alternate
-- contact.
--
-- 'httpStatus', 'getAlternateContactResponse_httpStatus' - The response's http status code.
newGetAlternateContactResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetAlternateContactResponse
newGetAlternateContactResponse :: Int -> GetAlternateContactResponse
newGetAlternateContactResponse Int
pHttpStatus_ =
  GetAlternateContactResponse' :: Maybe AlternateContact -> Int -> GetAlternateContactResponse
GetAlternateContactResponse'
    { $sel:alternateContact:GetAlternateContactResponse' :: Maybe AlternateContact
alternateContact =
        Maybe AlternateContact
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetAlternateContactResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains the details for the specified alternate
-- contact.
getAlternateContactResponse_alternateContact :: Lens.Lens' GetAlternateContactResponse (Prelude.Maybe AlternateContact)
getAlternateContactResponse_alternateContact :: (Maybe AlternateContact -> f (Maybe AlternateContact))
-> GetAlternateContactResponse -> f GetAlternateContactResponse
getAlternateContactResponse_alternateContact = (GetAlternateContactResponse -> Maybe AlternateContact)
-> (GetAlternateContactResponse
    -> Maybe AlternateContact -> GetAlternateContactResponse)
-> Lens
     GetAlternateContactResponse
     GetAlternateContactResponse
     (Maybe AlternateContact)
     (Maybe AlternateContact)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAlternateContactResponse' {Maybe AlternateContact
alternateContact :: Maybe AlternateContact
$sel:alternateContact:GetAlternateContactResponse' :: GetAlternateContactResponse -> Maybe AlternateContact
alternateContact} -> Maybe AlternateContact
alternateContact) (\s :: GetAlternateContactResponse
s@GetAlternateContactResponse' {} Maybe AlternateContact
a -> GetAlternateContactResponse
s {$sel:alternateContact:GetAlternateContactResponse' :: Maybe AlternateContact
alternateContact = Maybe AlternateContact
a} :: GetAlternateContactResponse)

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

instance Prelude.NFData GetAlternateContactResponse