{-# 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.Lightsail.GetContactMethods
-- 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)
--
-- Returns information about the configured contact methods. Specify a
-- protocol in your request to return information about a specific contact
-- method.
--
-- A contact method is used to send you notifications about your Amazon
-- Lightsail resources. You can add one email address and one mobile phone
-- number contact method in each AWS Region. However, SMS text messaging is
-- not supported in some AWS Regions, and SMS text messages cannot be sent
-- to some countries\/regions. For more information, see
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-notifications Notifications in Amazon Lightsail>.
module Amazonka.Lightsail.GetContactMethods
  ( -- * Creating a Request
    GetContactMethods (..),
    newGetContactMethods,

    -- * Request Lenses
    getContactMethods_protocols,

    -- * Destructuring the Response
    GetContactMethodsResponse (..),
    newGetContactMethodsResponse,

    -- * Response Lenses
    getContactMethodsResponse_contactMethods,
    getContactMethodsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetContactMethods' smart constructor.
data GetContactMethods = GetContactMethods'
  { -- | The protocols used to send notifications, such as @Email@, or @SMS@
    -- (text messaging).
    --
    -- Specify a protocol in your request to return information about a
    -- specific contact method protocol.
    GetContactMethods -> Maybe [ContactProtocol]
protocols :: Prelude.Maybe [ContactProtocol]
  }
  deriving (GetContactMethods -> GetContactMethods -> Bool
(GetContactMethods -> GetContactMethods -> Bool)
-> (GetContactMethods -> GetContactMethods -> Bool)
-> Eq GetContactMethods
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetContactMethods -> GetContactMethods -> Bool
$c/= :: GetContactMethods -> GetContactMethods -> Bool
== :: GetContactMethods -> GetContactMethods -> Bool
$c== :: GetContactMethods -> GetContactMethods -> Bool
Prelude.Eq, ReadPrec [GetContactMethods]
ReadPrec GetContactMethods
Int -> ReadS GetContactMethods
ReadS [GetContactMethods]
(Int -> ReadS GetContactMethods)
-> ReadS [GetContactMethods]
-> ReadPrec GetContactMethods
-> ReadPrec [GetContactMethods]
-> Read GetContactMethods
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetContactMethods]
$creadListPrec :: ReadPrec [GetContactMethods]
readPrec :: ReadPrec GetContactMethods
$creadPrec :: ReadPrec GetContactMethods
readList :: ReadS [GetContactMethods]
$creadList :: ReadS [GetContactMethods]
readsPrec :: Int -> ReadS GetContactMethods
$creadsPrec :: Int -> ReadS GetContactMethods
Prelude.Read, Int -> GetContactMethods -> ShowS
[GetContactMethods] -> ShowS
GetContactMethods -> String
(Int -> GetContactMethods -> ShowS)
-> (GetContactMethods -> String)
-> ([GetContactMethods] -> ShowS)
-> Show GetContactMethods
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetContactMethods] -> ShowS
$cshowList :: [GetContactMethods] -> ShowS
show :: GetContactMethods -> String
$cshow :: GetContactMethods -> String
showsPrec :: Int -> GetContactMethods -> ShowS
$cshowsPrec :: Int -> GetContactMethods -> ShowS
Prelude.Show, (forall x. GetContactMethods -> Rep GetContactMethods x)
-> (forall x. Rep GetContactMethods x -> GetContactMethods)
-> Generic GetContactMethods
forall x. Rep GetContactMethods x -> GetContactMethods
forall x. GetContactMethods -> Rep GetContactMethods x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetContactMethods x -> GetContactMethods
$cfrom :: forall x. GetContactMethods -> Rep GetContactMethods x
Prelude.Generic)

-- |
-- Create a value of 'GetContactMethods' 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:
--
-- 'protocols', 'getContactMethods_protocols' - The protocols used to send notifications, such as @Email@, or @SMS@
-- (text messaging).
--
-- Specify a protocol in your request to return information about a
-- specific contact method protocol.
newGetContactMethods ::
  GetContactMethods
newGetContactMethods :: GetContactMethods
newGetContactMethods =
  GetContactMethods' :: Maybe [ContactProtocol] -> GetContactMethods
GetContactMethods' {$sel:protocols:GetContactMethods' :: Maybe [ContactProtocol]
protocols = Maybe [ContactProtocol]
forall a. Maybe a
Prelude.Nothing}

-- | The protocols used to send notifications, such as @Email@, or @SMS@
-- (text messaging).
--
-- Specify a protocol in your request to return information about a
-- specific contact method protocol.
getContactMethods_protocols :: Lens.Lens' GetContactMethods (Prelude.Maybe [ContactProtocol])
getContactMethods_protocols :: (Maybe [ContactProtocol] -> f (Maybe [ContactProtocol]))
-> GetContactMethods -> f GetContactMethods
getContactMethods_protocols = (GetContactMethods -> Maybe [ContactProtocol])
-> (GetContactMethods
    -> Maybe [ContactProtocol] -> GetContactMethods)
-> Lens
     GetContactMethods
     GetContactMethods
     (Maybe [ContactProtocol])
     (Maybe [ContactProtocol])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContactMethods' {Maybe [ContactProtocol]
protocols :: Maybe [ContactProtocol]
$sel:protocols:GetContactMethods' :: GetContactMethods -> Maybe [ContactProtocol]
protocols} -> Maybe [ContactProtocol]
protocols) (\s :: GetContactMethods
s@GetContactMethods' {} Maybe [ContactProtocol]
a -> GetContactMethods
s {$sel:protocols:GetContactMethods' :: Maybe [ContactProtocol]
protocols = Maybe [ContactProtocol]
a} :: GetContactMethods) ((Maybe [ContactProtocol] -> f (Maybe [ContactProtocol]))
 -> GetContactMethods -> f GetContactMethods)
-> ((Maybe [ContactProtocol] -> f (Maybe [ContactProtocol]))
    -> Maybe [ContactProtocol] -> f (Maybe [ContactProtocol]))
-> (Maybe [ContactProtocol] -> f (Maybe [ContactProtocol]))
-> GetContactMethods
-> f GetContactMethods
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [ContactProtocol]
  [ContactProtocol]
  [ContactProtocol]
  [ContactProtocol]
-> Iso
     (Maybe [ContactProtocol])
     (Maybe [ContactProtocol])
     (Maybe [ContactProtocol])
     (Maybe [ContactProtocol])
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 AnIso
  [ContactProtocol]
  [ContactProtocol]
  [ContactProtocol]
  [ContactProtocol]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest GetContactMethods where
  type
    AWSResponse GetContactMethods =
      GetContactMethodsResponse
  request :: GetContactMethods -> Request GetContactMethods
request = Service -> GetContactMethods -> Request GetContactMethods
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetContactMethods
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetContactMethods)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetContactMethods))
-> Logger
-> Service
-> Proxy GetContactMethods
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetContactMethods)))
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 [ContactMethod] -> Int -> GetContactMethodsResponse
GetContactMethodsResponse'
            (Maybe [ContactMethod] -> Int -> GetContactMethodsResponse)
-> Either String (Maybe [ContactMethod])
-> Either String (Int -> GetContactMethodsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Key -> Either String (Maybe (Maybe [ContactMethod]))
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"contactMethods" Either String (Maybe (Maybe [ContactMethod]))
-> Maybe [ContactMethod] -> Either String (Maybe [ContactMethod])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [ContactMethod]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> GetContactMethodsResponse)
-> Either String Int -> Either String GetContactMethodsResponse
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 GetContactMethods

instance Prelude.NFData GetContactMethods

instance Core.ToHeaders GetContactMethods where
  toHeaders :: GetContactMethods -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetContactMethods -> 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
"Lightsail_20161128.GetContactMethods" ::
                          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 GetContactMethods where
  toJSON :: GetContactMethods -> Value
toJSON GetContactMethods' {Maybe [ContactProtocol]
protocols :: Maybe [ContactProtocol]
$sel:protocols:GetContactMethods' :: GetContactMethods -> Maybe [ContactProtocol]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"protocols" Key -> [ContactProtocol] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..=) ([ContactProtocol] -> Pair)
-> Maybe [ContactProtocol] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [ContactProtocol]
protocols]
      )

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

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

-- | /See:/ 'newGetContactMethodsResponse' smart constructor.
data GetContactMethodsResponse = GetContactMethodsResponse'
  { -- | An array of objects that describe the contact methods.
    GetContactMethodsResponse -> Maybe [ContactMethod]
contactMethods :: Prelude.Maybe [ContactMethod],
    -- | The response's http status code.
    GetContactMethodsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetContactMethodsResponse -> GetContactMethodsResponse -> Bool
(GetContactMethodsResponse -> GetContactMethodsResponse -> Bool)
-> (GetContactMethodsResponse -> GetContactMethodsResponse -> Bool)
-> Eq GetContactMethodsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetContactMethodsResponse -> GetContactMethodsResponse -> Bool
$c/= :: GetContactMethodsResponse -> GetContactMethodsResponse -> Bool
== :: GetContactMethodsResponse -> GetContactMethodsResponse -> Bool
$c== :: GetContactMethodsResponse -> GetContactMethodsResponse -> Bool
Prelude.Eq, ReadPrec [GetContactMethodsResponse]
ReadPrec GetContactMethodsResponse
Int -> ReadS GetContactMethodsResponse
ReadS [GetContactMethodsResponse]
(Int -> ReadS GetContactMethodsResponse)
-> ReadS [GetContactMethodsResponse]
-> ReadPrec GetContactMethodsResponse
-> ReadPrec [GetContactMethodsResponse]
-> Read GetContactMethodsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetContactMethodsResponse]
$creadListPrec :: ReadPrec [GetContactMethodsResponse]
readPrec :: ReadPrec GetContactMethodsResponse
$creadPrec :: ReadPrec GetContactMethodsResponse
readList :: ReadS [GetContactMethodsResponse]
$creadList :: ReadS [GetContactMethodsResponse]
readsPrec :: Int -> ReadS GetContactMethodsResponse
$creadsPrec :: Int -> ReadS GetContactMethodsResponse
Prelude.Read, Int -> GetContactMethodsResponse -> ShowS
[GetContactMethodsResponse] -> ShowS
GetContactMethodsResponse -> String
(Int -> GetContactMethodsResponse -> ShowS)
-> (GetContactMethodsResponse -> String)
-> ([GetContactMethodsResponse] -> ShowS)
-> Show GetContactMethodsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetContactMethodsResponse] -> ShowS
$cshowList :: [GetContactMethodsResponse] -> ShowS
show :: GetContactMethodsResponse -> String
$cshow :: GetContactMethodsResponse -> String
showsPrec :: Int -> GetContactMethodsResponse -> ShowS
$cshowsPrec :: Int -> GetContactMethodsResponse -> ShowS
Prelude.Show, (forall x.
 GetContactMethodsResponse -> Rep GetContactMethodsResponse x)
-> (forall x.
    Rep GetContactMethodsResponse x -> GetContactMethodsResponse)
-> Generic GetContactMethodsResponse
forall x.
Rep GetContactMethodsResponse x -> GetContactMethodsResponse
forall x.
GetContactMethodsResponse -> Rep GetContactMethodsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetContactMethodsResponse x -> GetContactMethodsResponse
$cfrom :: forall x.
GetContactMethodsResponse -> Rep GetContactMethodsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetContactMethodsResponse' 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:
--
-- 'contactMethods', 'getContactMethodsResponse_contactMethods' - An array of objects that describe the contact methods.
--
-- 'httpStatus', 'getContactMethodsResponse_httpStatus' - The response's http status code.
newGetContactMethodsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetContactMethodsResponse
newGetContactMethodsResponse :: Int -> GetContactMethodsResponse
newGetContactMethodsResponse Int
pHttpStatus_ =
  GetContactMethodsResponse' :: Maybe [ContactMethod] -> Int -> GetContactMethodsResponse
GetContactMethodsResponse'
    { $sel:contactMethods:GetContactMethodsResponse' :: Maybe [ContactMethod]
contactMethods =
        Maybe [ContactMethod]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetContactMethodsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the contact methods.
getContactMethodsResponse_contactMethods :: Lens.Lens' GetContactMethodsResponse (Prelude.Maybe [ContactMethod])
getContactMethodsResponse_contactMethods :: (Maybe [ContactMethod] -> f (Maybe [ContactMethod]))
-> GetContactMethodsResponse -> f GetContactMethodsResponse
getContactMethodsResponse_contactMethods = (GetContactMethodsResponse -> Maybe [ContactMethod])
-> (GetContactMethodsResponse
    -> Maybe [ContactMethod] -> GetContactMethodsResponse)
-> Lens
     GetContactMethodsResponse
     GetContactMethodsResponse
     (Maybe [ContactMethod])
     (Maybe [ContactMethod])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContactMethodsResponse' {Maybe [ContactMethod]
contactMethods :: Maybe [ContactMethod]
$sel:contactMethods:GetContactMethodsResponse' :: GetContactMethodsResponse -> Maybe [ContactMethod]
contactMethods} -> Maybe [ContactMethod]
contactMethods) (\s :: GetContactMethodsResponse
s@GetContactMethodsResponse' {} Maybe [ContactMethod]
a -> GetContactMethodsResponse
s {$sel:contactMethods:GetContactMethodsResponse' :: Maybe [ContactMethod]
contactMethods = Maybe [ContactMethod]
a} :: GetContactMethodsResponse) ((Maybe [ContactMethod] -> f (Maybe [ContactMethod]))
 -> GetContactMethodsResponse -> f GetContactMethodsResponse)
-> ((Maybe [ContactMethod] -> f (Maybe [ContactMethod]))
    -> Maybe [ContactMethod] -> f (Maybe [ContactMethod]))
-> (Maybe [ContactMethod] -> f (Maybe [ContactMethod]))
-> GetContactMethodsResponse
-> f GetContactMethodsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [ContactMethod] [ContactMethod] [ContactMethod] [ContactMethod]
-> Iso
     (Maybe [ContactMethod])
     (Maybe [ContactMethod])
     (Maybe [ContactMethod])
     (Maybe [ContactMethod])
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 AnIso
  [ContactMethod] [ContactMethod] [ContactMethod] [ContactMethod]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetContactMethodsResponse