{-# 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.Chime.UpdatePhoneNumber
-- 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)
--
-- Updates phone number details, such as product type or calling name, for
-- the specified phone number ID. You can update one phone number detail at
-- a time. For example, you can update either the product type or the
-- calling name in one action.
--
-- For toll-free numbers, you cannot use the Amazon Chime Business Calling
-- product type. For numbers outside the U.S., you must use the Amazon
-- Chime SIP Media Application Dial-In product type.
--
-- Updates to outbound calling names can take 72 hours to complete. Pending
-- updates to outbound calling names must be complete before you can
-- request another update.
module Amazonka.Chime.UpdatePhoneNumber
  ( -- * Creating a Request
    UpdatePhoneNumber (..),
    newUpdatePhoneNumber,

    -- * Request Lenses
    updatePhoneNumber_productType,
    updatePhoneNumber_callingName,
    updatePhoneNumber_phoneNumberId,

    -- * Destructuring the Response
    UpdatePhoneNumberResponse (..),
    newUpdatePhoneNumberResponse,

    -- * Response Lenses
    updatePhoneNumberResponse_phoneNumber,
    updatePhoneNumberResponse_httpStatus,
  )
where

import Amazonka.Chime.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:/ 'newUpdatePhoneNumber' smart constructor.
data UpdatePhoneNumber = UpdatePhoneNumber'
  { -- | The product type.
    UpdatePhoneNumber -> Maybe PhoneNumberProductType
productType :: Prelude.Maybe PhoneNumberProductType,
    -- | The outbound calling name associated with the phone number.
    UpdatePhoneNumber -> Maybe (Sensitive Text)
callingName :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The phone number ID.
    UpdatePhoneNumber -> Text
phoneNumberId :: Prelude.Text
  }
  deriving (UpdatePhoneNumber -> UpdatePhoneNumber -> Bool
(UpdatePhoneNumber -> UpdatePhoneNumber -> Bool)
-> (UpdatePhoneNumber -> UpdatePhoneNumber -> Bool)
-> Eq UpdatePhoneNumber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePhoneNumber -> UpdatePhoneNumber -> Bool
$c/= :: UpdatePhoneNumber -> UpdatePhoneNumber -> Bool
== :: UpdatePhoneNumber -> UpdatePhoneNumber -> Bool
$c== :: UpdatePhoneNumber -> UpdatePhoneNumber -> Bool
Prelude.Eq, Int -> UpdatePhoneNumber -> ShowS
[UpdatePhoneNumber] -> ShowS
UpdatePhoneNumber -> String
(Int -> UpdatePhoneNumber -> ShowS)
-> (UpdatePhoneNumber -> String)
-> ([UpdatePhoneNumber] -> ShowS)
-> Show UpdatePhoneNumber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePhoneNumber] -> ShowS
$cshowList :: [UpdatePhoneNumber] -> ShowS
show :: UpdatePhoneNumber -> String
$cshow :: UpdatePhoneNumber -> String
showsPrec :: Int -> UpdatePhoneNumber -> ShowS
$cshowsPrec :: Int -> UpdatePhoneNumber -> ShowS
Prelude.Show, (forall x. UpdatePhoneNumber -> Rep UpdatePhoneNumber x)
-> (forall x. Rep UpdatePhoneNumber x -> UpdatePhoneNumber)
-> Generic UpdatePhoneNumber
forall x. Rep UpdatePhoneNumber x -> UpdatePhoneNumber
forall x. UpdatePhoneNumber -> Rep UpdatePhoneNumber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdatePhoneNumber x -> UpdatePhoneNumber
$cfrom :: forall x. UpdatePhoneNumber -> Rep UpdatePhoneNumber x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePhoneNumber' 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:
--
-- 'productType', 'updatePhoneNumber_productType' - The product type.
--
-- 'callingName', 'updatePhoneNumber_callingName' - The outbound calling name associated with the phone number.
--
-- 'phoneNumberId', 'updatePhoneNumber_phoneNumberId' - The phone number ID.
newUpdatePhoneNumber ::
  -- | 'phoneNumberId'
  Prelude.Text ->
  UpdatePhoneNumber
newUpdatePhoneNumber :: Text -> UpdatePhoneNumber
newUpdatePhoneNumber Text
pPhoneNumberId_ =
  UpdatePhoneNumber' :: Maybe PhoneNumberProductType
-> Maybe (Sensitive Text) -> Text -> UpdatePhoneNumber
UpdatePhoneNumber'
    { $sel:productType:UpdatePhoneNumber' :: Maybe PhoneNumberProductType
productType = Maybe PhoneNumberProductType
forall a. Maybe a
Prelude.Nothing,
      $sel:callingName:UpdatePhoneNumber' :: Maybe (Sensitive Text)
callingName = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:phoneNumberId:UpdatePhoneNumber' :: Text
phoneNumberId = Text
pPhoneNumberId_
    }

-- | The product type.
updatePhoneNumber_productType :: Lens.Lens' UpdatePhoneNumber (Prelude.Maybe PhoneNumberProductType)
updatePhoneNumber_productType :: (Maybe PhoneNumberProductType -> f (Maybe PhoneNumberProductType))
-> UpdatePhoneNumber -> f UpdatePhoneNumber
updatePhoneNumber_productType = (UpdatePhoneNumber -> Maybe PhoneNumberProductType)
-> (UpdatePhoneNumber
    -> Maybe PhoneNumberProductType -> UpdatePhoneNumber)
-> Lens
     UpdatePhoneNumber
     UpdatePhoneNumber
     (Maybe PhoneNumberProductType)
     (Maybe PhoneNumberProductType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePhoneNumber' {Maybe PhoneNumberProductType
productType :: Maybe PhoneNumberProductType
$sel:productType:UpdatePhoneNumber' :: UpdatePhoneNumber -> Maybe PhoneNumberProductType
productType} -> Maybe PhoneNumberProductType
productType) (\s :: UpdatePhoneNumber
s@UpdatePhoneNumber' {} Maybe PhoneNumberProductType
a -> UpdatePhoneNumber
s {$sel:productType:UpdatePhoneNumber' :: Maybe PhoneNumberProductType
productType = Maybe PhoneNumberProductType
a} :: UpdatePhoneNumber)

-- | The outbound calling name associated with the phone number.
updatePhoneNumber_callingName :: Lens.Lens' UpdatePhoneNumber (Prelude.Maybe Prelude.Text)
updatePhoneNumber_callingName :: (Maybe Text -> f (Maybe Text))
-> UpdatePhoneNumber -> f UpdatePhoneNumber
updatePhoneNumber_callingName = (UpdatePhoneNumber -> Maybe (Sensitive Text))
-> (UpdatePhoneNumber
    -> Maybe (Sensitive Text) -> UpdatePhoneNumber)
-> Lens
     UpdatePhoneNumber
     UpdatePhoneNumber
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePhoneNumber' {Maybe (Sensitive Text)
callingName :: Maybe (Sensitive Text)
$sel:callingName:UpdatePhoneNumber' :: UpdatePhoneNumber -> Maybe (Sensitive Text)
callingName} -> Maybe (Sensitive Text)
callingName) (\s :: UpdatePhoneNumber
s@UpdatePhoneNumber' {} Maybe (Sensitive Text)
a -> UpdatePhoneNumber
s {$sel:callingName:UpdatePhoneNumber' :: Maybe (Sensitive Text)
callingName = Maybe (Sensitive Text)
a} :: UpdatePhoneNumber) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> UpdatePhoneNumber -> f UpdatePhoneNumber)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> UpdatePhoneNumber
-> f UpdatePhoneNumber
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe Text)
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 (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The phone number ID.
updatePhoneNumber_phoneNumberId :: Lens.Lens' UpdatePhoneNumber Prelude.Text
updatePhoneNumber_phoneNumberId :: (Text -> f Text) -> UpdatePhoneNumber -> f UpdatePhoneNumber
updatePhoneNumber_phoneNumberId = (UpdatePhoneNumber -> Text)
-> (UpdatePhoneNumber -> Text -> UpdatePhoneNumber)
-> Lens UpdatePhoneNumber UpdatePhoneNumber Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePhoneNumber' {Text
phoneNumberId :: Text
$sel:phoneNumberId:UpdatePhoneNumber' :: UpdatePhoneNumber -> Text
phoneNumberId} -> Text
phoneNumberId) (\s :: UpdatePhoneNumber
s@UpdatePhoneNumber' {} Text
a -> UpdatePhoneNumber
s {$sel:phoneNumberId:UpdatePhoneNumber' :: Text
phoneNumberId = Text
a} :: UpdatePhoneNumber)

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

instance Prelude.NFData UpdatePhoneNumber

instance Core.ToHeaders UpdatePhoneNumber where
  toHeaders :: UpdatePhoneNumber -> ResponseHeaders
toHeaders = ResponseHeaders -> UpdatePhoneNumber -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON UpdatePhoneNumber where
  toJSON :: UpdatePhoneNumber -> Value
toJSON UpdatePhoneNumber' {Maybe (Sensitive Text)
Maybe PhoneNumberProductType
Text
phoneNumberId :: Text
callingName :: Maybe (Sensitive Text)
productType :: Maybe PhoneNumberProductType
$sel:phoneNumberId:UpdatePhoneNumber' :: UpdatePhoneNumber -> Text
$sel:callingName:UpdatePhoneNumber' :: UpdatePhoneNumber -> Maybe (Sensitive Text)
$sel:productType:UpdatePhoneNumber' :: UpdatePhoneNumber -> Maybe PhoneNumberProductType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ProductType" Text -> PhoneNumberProductType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (PhoneNumberProductType -> Pair)
-> Maybe PhoneNumberProductType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PhoneNumberProductType
productType,
            (Text
"CallingName" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Sensitive Text -> Pair) -> Maybe (Sensitive Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Text)
callingName
          ]
      )

instance Core.ToPath UpdatePhoneNumber where
  toPath :: UpdatePhoneNumber -> ByteString
toPath UpdatePhoneNumber' {Maybe (Sensitive Text)
Maybe PhoneNumberProductType
Text
phoneNumberId :: Text
callingName :: Maybe (Sensitive Text)
productType :: Maybe PhoneNumberProductType
$sel:phoneNumberId:UpdatePhoneNumber' :: UpdatePhoneNumber -> Text
$sel:callingName:UpdatePhoneNumber' :: UpdatePhoneNumber -> Maybe (Sensitive Text)
$sel:productType:UpdatePhoneNumber' :: UpdatePhoneNumber -> Maybe PhoneNumberProductType
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/phone-numbers/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
phoneNumberId]

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

-- | /See:/ 'newUpdatePhoneNumberResponse' smart constructor.
data UpdatePhoneNumberResponse = UpdatePhoneNumberResponse'
  { -- | The updated phone number details.
    UpdatePhoneNumberResponse -> Maybe PhoneNumber
phoneNumber :: Prelude.Maybe PhoneNumber,
    -- | The response's http status code.
    UpdatePhoneNumberResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdatePhoneNumberResponse -> UpdatePhoneNumberResponse -> Bool
(UpdatePhoneNumberResponse -> UpdatePhoneNumberResponse -> Bool)
-> (UpdatePhoneNumberResponse -> UpdatePhoneNumberResponse -> Bool)
-> Eq UpdatePhoneNumberResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePhoneNumberResponse -> UpdatePhoneNumberResponse -> Bool
$c/= :: UpdatePhoneNumberResponse -> UpdatePhoneNumberResponse -> Bool
== :: UpdatePhoneNumberResponse -> UpdatePhoneNumberResponse -> Bool
$c== :: UpdatePhoneNumberResponse -> UpdatePhoneNumberResponse -> Bool
Prelude.Eq, Int -> UpdatePhoneNumberResponse -> ShowS
[UpdatePhoneNumberResponse] -> ShowS
UpdatePhoneNumberResponse -> String
(Int -> UpdatePhoneNumberResponse -> ShowS)
-> (UpdatePhoneNumberResponse -> String)
-> ([UpdatePhoneNumberResponse] -> ShowS)
-> Show UpdatePhoneNumberResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePhoneNumberResponse] -> ShowS
$cshowList :: [UpdatePhoneNumberResponse] -> ShowS
show :: UpdatePhoneNumberResponse -> String
$cshow :: UpdatePhoneNumberResponse -> String
showsPrec :: Int -> UpdatePhoneNumberResponse -> ShowS
$cshowsPrec :: Int -> UpdatePhoneNumberResponse -> ShowS
Prelude.Show, (forall x.
 UpdatePhoneNumberResponse -> Rep UpdatePhoneNumberResponse x)
-> (forall x.
    Rep UpdatePhoneNumberResponse x -> UpdatePhoneNumberResponse)
-> Generic UpdatePhoneNumberResponse
forall x.
Rep UpdatePhoneNumberResponse x -> UpdatePhoneNumberResponse
forall x.
UpdatePhoneNumberResponse -> Rep UpdatePhoneNumberResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdatePhoneNumberResponse x -> UpdatePhoneNumberResponse
$cfrom :: forall x.
UpdatePhoneNumberResponse -> Rep UpdatePhoneNumberResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePhoneNumberResponse' 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:
--
-- 'phoneNumber', 'updatePhoneNumberResponse_phoneNumber' - The updated phone number details.
--
-- 'httpStatus', 'updatePhoneNumberResponse_httpStatus' - The response's http status code.
newUpdatePhoneNumberResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdatePhoneNumberResponse
newUpdatePhoneNumberResponse :: Int -> UpdatePhoneNumberResponse
newUpdatePhoneNumberResponse Int
pHttpStatus_ =
  UpdatePhoneNumberResponse' :: Maybe PhoneNumber -> Int -> UpdatePhoneNumberResponse
UpdatePhoneNumberResponse'
    { $sel:phoneNumber:UpdatePhoneNumberResponse' :: Maybe PhoneNumber
phoneNumber =
        Maybe PhoneNumber
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdatePhoneNumberResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The updated phone number details.
updatePhoneNumberResponse_phoneNumber :: Lens.Lens' UpdatePhoneNumberResponse (Prelude.Maybe PhoneNumber)
updatePhoneNumberResponse_phoneNumber :: (Maybe PhoneNumber -> f (Maybe PhoneNumber))
-> UpdatePhoneNumberResponse -> f UpdatePhoneNumberResponse
updatePhoneNumberResponse_phoneNumber = (UpdatePhoneNumberResponse -> Maybe PhoneNumber)
-> (UpdatePhoneNumberResponse
    -> Maybe PhoneNumber -> UpdatePhoneNumberResponse)
-> Lens
     UpdatePhoneNumberResponse
     UpdatePhoneNumberResponse
     (Maybe PhoneNumber)
     (Maybe PhoneNumber)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePhoneNumberResponse' {Maybe PhoneNumber
phoneNumber :: Maybe PhoneNumber
$sel:phoneNumber:UpdatePhoneNumberResponse' :: UpdatePhoneNumberResponse -> Maybe PhoneNumber
phoneNumber} -> Maybe PhoneNumber
phoneNumber) (\s :: UpdatePhoneNumberResponse
s@UpdatePhoneNumberResponse' {} Maybe PhoneNumber
a -> UpdatePhoneNumberResponse
s {$sel:phoneNumber:UpdatePhoneNumberResponse' :: Maybe PhoneNumber
phoneNumber = Maybe PhoneNumber
a} :: UpdatePhoneNumberResponse)

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

instance Prelude.NFData UpdatePhoneNumberResponse