{-# 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.GetContact
-- 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 the contact details by the contact ARN.
module Amazonka.AlexaBusiness.GetContact
  ( -- * Creating a Request
    GetContact (..),
    newGetContact,

    -- * Request Lenses
    getContact_contactArn,

    -- * Destructuring the Response
    GetContactResponse (..),
    newGetContactResponse,

    -- * Response Lenses
    getContactResponse_contact,
    getContactResponse_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:/ 'newGetContact' smart constructor.
data GetContact = GetContact'
  { -- | The ARN of the contact for which to request details.
    GetContact -> Text
contactArn :: Prelude.Text
  }
  deriving (GetContact -> GetContact -> Bool
(GetContact -> GetContact -> Bool)
-> (GetContact -> GetContact -> Bool) -> Eq GetContact
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetContact -> GetContact -> Bool
$c/= :: GetContact -> GetContact -> Bool
== :: GetContact -> GetContact -> Bool
$c== :: GetContact -> GetContact -> Bool
Prelude.Eq, ReadPrec [GetContact]
ReadPrec GetContact
Int -> ReadS GetContact
ReadS [GetContact]
(Int -> ReadS GetContact)
-> ReadS [GetContact]
-> ReadPrec GetContact
-> ReadPrec [GetContact]
-> Read GetContact
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetContact]
$creadListPrec :: ReadPrec [GetContact]
readPrec :: ReadPrec GetContact
$creadPrec :: ReadPrec GetContact
readList :: ReadS [GetContact]
$creadList :: ReadS [GetContact]
readsPrec :: Int -> ReadS GetContact
$creadsPrec :: Int -> ReadS GetContact
Prelude.Read, Int -> GetContact -> ShowS
[GetContact] -> ShowS
GetContact -> String
(Int -> GetContact -> ShowS)
-> (GetContact -> String)
-> ([GetContact] -> ShowS)
-> Show GetContact
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetContact] -> ShowS
$cshowList :: [GetContact] -> ShowS
show :: GetContact -> String
$cshow :: GetContact -> String
showsPrec :: Int -> GetContact -> ShowS
$cshowsPrec :: Int -> GetContact -> ShowS
Prelude.Show, (forall x. GetContact -> Rep GetContact x)
-> (forall x. Rep GetContact x -> GetContact) -> Generic GetContact
forall x. Rep GetContact x -> GetContact
forall x. GetContact -> Rep GetContact x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetContact x -> GetContact
$cfrom :: forall x. GetContact -> Rep GetContact x
Prelude.Generic)

-- |
-- Create a value of 'GetContact' 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:
--
-- 'contactArn', 'getContact_contactArn' - The ARN of the contact for which to request details.
newGetContact ::
  -- | 'contactArn'
  Prelude.Text ->
  GetContact
newGetContact :: Text -> GetContact
newGetContact Text
pContactArn_ =
  GetContact' :: Text -> GetContact
GetContact' {$sel:contactArn:GetContact' :: Text
contactArn = Text
pContactArn_}

-- | The ARN of the contact for which to request details.
getContact_contactArn :: Lens.Lens' GetContact Prelude.Text
getContact_contactArn :: (Text -> f Text) -> GetContact -> f GetContact
getContact_contactArn = (GetContact -> Text)
-> (GetContact -> Text -> GetContact)
-> Lens GetContact GetContact Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContact' {Text
contactArn :: Text
$sel:contactArn:GetContact' :: GetContact -> Text
contactArn} -> Text
contactArn) (\s :: GetContact
s@GetContact' {} Text
a -> GetContact
s {$sel:contactArn:GetContact' :: Text
contactArn = Text
a} :: GetContact)

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

instance Prelude.NFData GetContact

instance Core.ToHeaders GetContact where
  toHeaders :: GetContact -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetContact -> 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.GetContact" ::
                          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 GetContact where
  toJSON :: GetContact -> Value
toJSON GetContact' {Text
contactArn :: Text
$sel:contactArn:GetContact' :: GetContact -> 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
"ContactArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
contactArn)]
      )

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

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

-- | /See:/ 'newGetContactResponse' smart constructor.
data GetContactResponse = GetContactResponse'
  { -- | The details of the requested contact.
    GetContactResponse -> Maybe Contact
contact :: Prelude.Maybe Contact,
    -- | The response's http status code.
    GetContactResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetContactResponse -> GetContactResponse -> Bool
(GetContactResponse -> GetContactResponse -> Bool)
-> (GetContactResponse -> GetContactResponse -> Bool)
-> Eq GetContactResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetContactResponse -> GetContactResponse -> Bool
$c/= :: GetContactResponse -> GetContactResponse -> Bool
== :: GetContactResponse -> GetContactResponse -> Bool
$c== :: GetContactResponse -> GetContactResponse -> Bool
Prelude.Eq, Int -> GetContactResponse -> ShowS
[GetContactResponse] -> ShowS
GetContactResponse -> String
(Int -> GetContactResponse -> ShowS)
-> (GetContactResponse -> String)
-> ([GetContactResponse] -> ShowS)
-> Show GetContactResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetContactResponse] -> ShowS
$cshowList :: [GetContactResponse] -> ShowS
show :: GetContactResponse -> String
$cshow :: GetContactResponse -> String
showsPrec :: Int -> GetContactResponse -> ShowS
$cshowsPrec :: Int -> GetContactResponse -> ShowS
Prelude.Show, (forall x. GetContactResponse -> Rep GetContactResponse x)
-> (forall x. Rep GetContactResponse x -> GetContactResponse)
-> Generic GetContactResponse
forall x. Rep GetContactResponse x -> GetContactResponse
forall x. GetContactResponse -> Rep GetContactResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetContactResponse x -> GetContactResponse
$cfrom :: forall x. GetContactResponse -> Rep GetContactResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetContactResponse' 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:
--
-- 'contact', 'getContactResponse_contact' - The details of the requested contact.
--
-- 'httpStatus', 'getContactResponse_httpStatus' - The response's http status code.
newGetContactResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetContactResponse
newGetContactResponse :: Int -> GetContactResponse
newGetContactResponse Int
pHttpStatus_ =
  GetContactResponse' :: Maybe Contact -> Int -> GetContactResponse
GetContactResponse'
    { $sel:contact:GetContactResponse' :: Maybe Contact
contact = Maybe Contact
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetContactResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The details of the requested contact.
getContactResponse_contact :: Lens.Lens' GetContactResponse (Prelude.Maybe Contact)
getContactResponse_contact :: (Maybe Contact -> f (Maybe Contact))
-> GetContactResponse -> f GetContactResponse
getContactResponse_contact = (GetContactResponse -> Maybe Contact)
-> (GetContactResponse -> Maybe Contact -> GetContactResponse)
-> Lens
     GetContactResponse
     GetContactResponse
     (Maybe Contact)
     (Maybe Contact)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContactResponse' {Maybe Contact
contact :: Maybe Contact
$sel:contact:GetContactResponse' :: GetContactResponse -> Maybe Contact
contact} -> Maybe Contact
contact) (\s :: GetContactResponse
s@GetContactResponse' {} Maybe Contact
a -> GetContactResponse
s {$sel:contact:GetContactResponse' :: Maybe Contact
contact = Maybe Contact
a} :: GetContactResponse)

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

instance Prelude.NFData GetContactResponse