{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 Amazon Web Services Region. However, SMS
-- text messaging is not supported in some Amazon Web Services 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$sel:protocols:GetContactMethods' :: Maybe [ContactProtocol]
protocols = 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 :: Lens' GetContactMethods (Maybe [ContactProtocol])
getContactMethods_protocols = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: (Service -> Service)
-> GetContactMethods -> Request GetContactMethods
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 GetContactMethods
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetContactMethods)))
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 [ContactMethod] -> Int -> GetContactMethodsResponse
GetContactMethodsResponse'
            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
"contactMethods" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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 GetContactMethods where
  hashWithSalt :: Int -> GetContactMethods -> Int
hashWithSalt Int
_salt GetContactMethods' {Maybe [ContactProtocol]
protocols :: Maybe [ContactProtocol]
$sel:protocols:GetContactMethods' :: GetContactMethods -> Maybe [ContactProtocol]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ContactProtocol]
protocols

instance Prelude.NFData GetContactMethods where
  rnf :: GetContactMethods -> ()
rnf GetContactMethods' {Maybe [ContactProtocol]
protocols :: Maybe [ContactProtocol]
$sel:protocols:GetContactMethods' :: GetContactMethods -> Maybe [ContactProtocol]
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe [ContactProtocol]
protocols

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

instance Data.ToJSON GetContactMethods where
  toJSON :: GetContactMethods -> Value
toJSON GetContactMethods' {Maybe [ContactProtocol]
protocols :: Maybe [ContactProtocol]
$sel:protocols:GetContactMethods' :: GetContactMethods -> Maybe [ContactProtocol]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"protocols" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [ContactProtocol]
protocols]
      )

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

instance Data.ToQuery GetContactMethods where
  toQuery :: GetContactMethods -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:contactMethods:GetContactMethodsResponse' :: Maybe [ContactMethod]
contactMethods =
        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 :: Lens' GetContactMethodsResponse (Maybe [ContactMethod])
getContactMethodsResponse_contactMethods = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' GetContactMethodsResponse Int
getContactMethodsResponse_httpStatus = 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 where
  rnf :: GetContactMethodsResponse -> ()
rnf GetContactMethodsResponse' {Int
Maybe [ContactMethod]
httpStatus :: Int
contactMethods :: Maybe [ContactMethod]
$sel:httpStatus:GetContactMethodsResponse' :: GetContactMethodsResponse -> Int
$sel:contactMethods:GetContactMethodsResponse' :: GetContactMethodsResponse -> Maybe [ContactMethod]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ContactMethod]
contactMethods
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus