{-# 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.AlexaBusiness.GetAddressBook
-- 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)
--
-- Gets address the book details by the address book ARN.
module Amazonka.AlexaBusiness.GetAddressBook
  ( -- * Creating a Request
    GetAddressBook (..),
    newGetAddressBook,

    -- * Request Lenses
    getAddressBook_addressBookArn,

    -- * Destructuring the Response
    GetAddressBookResponse (..),
    newGetAddressBookResponse,

    -- * Response Lenses
    getAddressBookResponse_addressBook,
    getAddressBookResponse_httpStatus,
  )
where

import Amazonka.AlexaBusiness.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:/ 'newGetAddressBook' smart constructor.
data GetAddressBook = GetAddressBook'
  { -- | The ARN of the address book for which to request details.
    GetAddressBook -> Text
addressBookArn :: Prelude.Text
  }
  deriving (GetAddressBook -> GetAddressBook -> Bool
(GetAddressBook -> GetAddressBook -> Bool)
-> (GetAddressBook -> GetAddressBook -> Bool) -> Eq GetAddressBook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAddressBook -> GetAddressBook -> Bool
$c/= :: GetAddressBook -> GetAddressBook -> Bool
== :: GetAddressBook -> GetAddressBook -> Bool
$c== :: GetAddressBook -> GetAddressBook -> Bool
Prelude.Eq, ReadPrec [GetAddressBook]
ReadPrec GetAddressBook
Int -> ReadS GetAddressBook
ReadS [GetAddressBook]
(Int -> ReadS GetAddressBook)
-> ReadS [GetAddressBook]
-> ReadPrec GetAddressBook
-> ReadPrec [GetAddressBook]
-> Read GetAddressBook
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAddressBook]
$creadListPrec :: ReadPrec [GetAddressBook]
readPrec :: ReadPrec GetAddressBook
$creadPrec :: ReadPrec GetAddressBook
readList :: ReadS [GetAddressBook]
$creadList :: ReadS [GetAddressBook]
readsPrec :: Int -> ReadS GetAddressBook
$creadsPrec :: Int -> ReadS GetAddressBook
Prelude.Read, Int -> GetAddressBook -> ShowS
[GetAddressBook] -> ShowS
GetAddressBook -> String
(Int -> GetAddressBook -> ShowS)
-> (GetAddressBook -> String)
-> ([GetAddressBook] -> ShowS)
-> Show GetAddressBook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAddressBook] -> ShowS
$cshowList :: [GetAddressBook] -> ShowS
show :: GetAddressBook -> String
$cshow :: GetAddressBook -> String
showsPrec :: Int -> GetAddressBook -> ShowS
$cshowsPrec :: Int -> GetAddressBook -> ShowS
Prelude.Show, (forall x. GetAddressBook -> Rep GetAddressBook x)
-> (forall x. Rep GetAddressBook x -> GetAddressBook)
-> Generic GetAddressBook
forall x. Rep GetAddressBook x -> GetAddressBook
forall x. GetAddressBook -> Rep GetAddressBook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAddressBook x -> GetAddressBook
$cfrom :: forall x. GetAddressBook -> Rep GetAddressBook x
Prelude.Generic)

-- |
-- Create a value of 'GetAddressBook' 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:
--
-- 'addressBookArn', 'getAddressBook_addressBookArn' - The ARN of the address book for which to request details.
newGetAddressBook ::
  -- | 'addressBookArn'
  Prelude.Text ->
  GetAddressBook
newGetAddressBook :: Text -> GetAddressBook
newGetAddressBook Text
pAddressBookArn_ =
  GetAddressBook' :: Text -> GetAddressBook
GetAddressBook' {$sel:addressBookArn:GetAddressBook' :: Text
addressBookArn = Text
pAddressBookArn_}

-- | The ARN of the address book for which to request details.
getAddressBook_addressBookArn :: Lens.Lens' GetAddressBook Prelude.Text
getAddressBook_addressBookArn :: (Text -> f Text) -> GetAddressBook -> f GetAddressBook
getAddressBook_addressBookArn = (GetAddressBook -> Text)
-> (GetAddressBook -> Text -> GetAddressBook)
-> Lens GetAddressBook GetAddressBook Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAddressBook' {Text
addressBookArn :: Text
$sel:addressBookArn:GetAddressBook' :: GetAddressBook -> Text
addressBookArn} -> Text
addressBookArn) (\s :: GetAddressBook
s@GetAddressBook' {} Text
a -> GetAddressBook
s {$sel:addressBookArn:GetAddressBook' :: Text
addressBookArn = Text
a} :: GetAddressBook)

instance Core.AWSRequest GetAddressBook where
  type
    AWSResponse GetAddressBook =
      GetAddressBookResponse
  request :: GetAddressBook -> Request GetAddressBook
request = Service -> GetAddressBook -> Request GetAddressBook
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetAddressBook
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAddressBook)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetAddressBook))
-> Logger
-> Service
-> Proxy GetAddressBook
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAddressBook)))
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 AddressBook -> Int -> GetAddressBookResponse
GetAddressBookResponse'
            (Maybe AddressBook -> Int -> GetAddressBookResponse)
-> Either String (Maybe AddressBook)
-> Either String (Int -> GetAddressBookResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe AddressBook)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"AddressBook")
            Either String (Int -> GetAddressBookResponse)
-> Either String Int -> Either String GetAddressBookResponse
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 GetAddressBook

instance Prelude.NFData GetAddressBook

instance Core.ToHeaders GetAddressBook where
  toHeaders :: GetAddressBook -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetAddressBook -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AlexaForBusiness.GetAddressBook" ::
                          Prelude.ByteString
                      ),
            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 GetAddressBook where
  toJSON :: GetAddressBook -> Value
toJSON GetAddressBook' {Text
addressBookArn :: Text
$sel:addressBookArn:GetAddressBook' :: GetAddressBook -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AddressBookArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
addressBookArn)
          ]
      )

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

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

-- | /See:/ 'newGetAddressBookResponse' smart constructor.
data GetAddressBookResponse = GetAddressBookResponse'
  { -- | The details of the requested address book.
    GetAddressBookResponse -> Maybe AddressBook
addressBook :: Prelude.Maybe AddressBook,
    -- | The response's http status code.
    GetAddressBookResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetAddressBookResponse -> GetAddressBookResponse -> Bool
(GetAddressBookResponse -> GetAddressBookResponse -> Bool)
-> (GetAddressBookResponse -> GetAddressBookResponse -> Bool)
-> Eq GetAddressBookResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAddressBookResponse -> GetAddressBookResponse -> Bool
$c/= :: GetAddressBookResponse -> GetAddressBookResponse -> Bool
== :: GetAddressBookResponse -> GetAddressBookResponse -> Bool
$c== :: GetAddressBookResponse -> GetAddressBookResponse -> Bool
Prelude.Eq, ReadPrec [GetAddressBookResponse]
ReadPrec GetAddressBookResponse
Int -> ReadS GetAddressBookResponse
ReadS [GetAddressBookResponse]
(Int -> ReadS GetAddressBookResponse)
-> ReadS [GetAddressBookResponse]
-> ReadPrec GetAddressBookResponse
-> ReadPrec [GetAddressBookResponse]
-> Read GetAddressBookResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAddressBookResponse]
$creadListPrec :: ReadPrec [GetAddressBookResponse]
readPrec :: ReadPrec GetAddressBookResponse
$creadPrec :: ReadPrec GetAddressBookResponse
readList :: ReadS [GetAddressBookResponse]
$creadList :: ReadS [GetAddressBookResponse]
readsPrec :: Int -> ReadS GetAddressBookResponse
$creadsPrec :: Int -> ReadS GetAddressBookResponse
Prelude.Read, Int -> GetAddressBookResponse -> ShowS
[GetAddressBookResponse] -> ShowS
GetAddressBookResponse -> String
(Int -> GetAddressBookResponse -> ShowS)
-> (GetAddressBookResponse -> String)
-> ([GetAddressBookResponse] -> ShowS)
-> Show GetAddressBookResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAddressBookResponse] -> ShowS
$cshowList :: [GetAddressBookResponse] -> ShowS
show :: GetAddressBookResponse -> String
$cshow :: GetAddressBookResponse -> String
showsPrec :: Int -> GetAddressBookResponse -> ShowS
$cshowsPrec :: Int -> GetAddressBookResponse -> ShowS
Prelude.Show, (forall x. GetAddressBookResponse -> Rep GetAddressBookResponse x)
-> (forall x.
    Rep GetAddressBookResponse x -> GetAddressBookResponse)
-> Generic GetAddressBookResponse
forall x. Rep GetAddressBookResponse x -> GetAddressBookResponse
forall x. GetAddressBookResponse -> Rep GetAddressBookResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAddressBookResponse x -> GetAddressBookResponse
$cfrom :: forall x. GetAddressBookResponse -> Rep GetAddressBookResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetAddressBookResponse' 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:
--
-- 'addressBook', 'getAddressBookResponse_addressBook' - The details of the requested address book.
--
-- 'httpStatus', 'getAddressBookResponse_httpStatus' - The response's http status code.
newGetAddressBookResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetAddressBookResponse
newGetAddressBookResponse :: Int -> GetAddressBookResponse
newGetAddressBookResponse Int
pHttpStatus_ =
  GetAddressBookResponse' :: Maybe AddressBook -> Int -> GetAddressBookResponse
GetAddressBookResponse'
    { $sel:addressBook:GetAddressBookResponse' :: Maybe AddressBook
addressBook =
        Maybe AddressBook
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetAddressBookResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The details of the requested address book.
getAddressBookResponse_addressBook :: Lens.Lens' GetAddressBookResponse (Prelude.Maybe AddressBook)
getAddressBookResponse_addressBook :: (Maybe AddressBook -> f (Maybe AddressBook))
-> GetAddressBookResponse -> f GetAddressBookResponse
getAddressBookResponse_addressBook = (GetAddressBookResponse -> Maybe AddressBook)
-> (GetAddressBookResponse
    -> Maybe AddressBook -> GetAddressBookResponse)
-> Lens
     GetAddressBookResponse
     GetAddressBookResponse
     (Maybe AddressBook)
     (Maybe AddressBook)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAddressBookResponse' {Maybe AddressBook
addressBook :: Maybe AddressBook
$sel:addressBook:GetAddressBookResponse' :: GetAddressBookResponse -> Maybe AddressBook
addressBook} -> Maybe AddressBook
addressBook) (\s :: GetAddressBookResponse
s@GetAddressBookResponse' {} Maybe AddressBook
a -> GetAddressBookResponse
s {$sel:addressBook:GetAddressBookResponse' :: Maybe AddressBook
addressBook = Maybe AddressBook
a} :: GetAddressBookResponse)

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

instance Prelude.NFData GetAddressBookResponse