{-# 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.Route53AutoNaming.UpdateService
-- 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)
--
-- Submits a request to perform the following operations:
--
-- -   Update the TTL setting for existing @DnsRecords@ configurations
--
-- -   Add, update, or delete @HealthCheckConfig@ for a specified service
--
--     You can\'t add, update, or delete a @HealthCheckCustomConfig@
--     configuration.
--
-- For public and private DNS namespaces, note the following:
--
-- -   If you omit any existing @DnsRecords@ or @HealthCheckConfig@
--     configurations from an @UpdateService@ request, the configurations
--     are deleted from the service.
--
-- -   If you omit an existing @HealthCheckCustomConfig@ configuration from
--     an @UpdateService@ request, the configuration isn\'t deleted from
--     the service.
--
-- When you update settings for a service, Cloud Map also updates the
-- corresponding settings in all the records and health checks that were
-- created by using the specified service.
module Amazonka.Route53AutoNaming.UpdateService
  ( -- * Creating a Request
    UpdateService (..),
    newUpdateService,

    -- * Request Lenses
    updateService_id,
    updateService_service,

    -- * Destructuring the Response
    UpdateServiceResponse (..),
    newUpdateServiceResponse,

    -- * Response Lenses
    updateServiceResponse_operationId,
    updateServiceResponse_httpStatus,
  )
where

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
import Amazonka.Route53AutoNaming.Types

-- | /See:/ 'newUpdateService' smart constructor.
data UpdateService = UpdateService'
  { -- | The ID of the service that you want to update.
    UpdateService -> Text
id :: Prelude.Text,
    -- | A complex type that contains the new settings for the service.
    UpdateService -> ServiceChange
service :: ServiceChange
  }
  deriving (UpdateService -> UpdateService -> Bool
(UpdateService -> UpdateService -> Bool)
-> (UpdateService -> UpdateService -> Bool) -> Eq UpdateService
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateService -> UpdateService -> Bool
$c/= :: UpdateService -> UpdateService -> Bool
== :: UpdateService -> UpdateService -> Bool
$c== :: UpdateService -> UpdateService -> Bool
Prelude.Eq, ReadPrec [UpdateService]
ReadPrec UpdateService
Int -> ReadS UpdateService
ReadS [UpdateService]
(Int -> ReadS UpdateService)
-> ReadS [UpdateService]
-> ReadPrec UpdateService
-> ReadPrec [UpdateService]
-> Read UpdateService
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateService]
$creadListPrec :: ReadPrec [UpdateService]
readPrec :: ReadPrec UpdateService
$creadPrec :: ReadPrec UpdateService
readList :: ReadS [UpdateService]
$creadList :: ReadS [UpdateService]
readsPrec :: Int -> ReadS UpdateService
$creadsPrec :: Int -> ReadS UpdateService
Prelude.Read, Int -> UpdateService -> ShowS
[UpdateService] -> ShowS
UpdateService -> String
(Int -> UpdateService -> ShowS)
-> (UpdateService -> String)
-> ([UpdateService] -> ShowS)
-> Show UpdateService
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateService] -> ShowS
$cshowList :: [UpdateService] -> ShowS
show :: UpdateService -> String
$cshow :: UpdateService -> String
showsPrec :: Int -> UpdateService -> ShowS
$cshowsPrec :: Int -> UpdateService -> ShowS
Prelude.Show, (forall x. UpdateService -> Rep UpdateService x)
-> (forall x. Rep UpdateService x -> UpdateService)
-> Generic UpdateService
forall x. Rep UpdateService x -> UpdateService
forall x. UpdateService -> Rep UpdateService x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateService x -> UpdateService
$cfrom :: forall x. UpdateService -> Rep UpdateService x
Prelude.Generic)

-- |
-- Create a value of 'UpdateService' 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:
--
-- 'id', 'updateService_id' - The ID of the service that you want to update.
--
-- 'service', 'updateService_service' - A complex type that contains the new settings for the service.
newUpdateService ::
  -- | 'id'
  Prelude.Text ->
  -- | 'service'
  ServiceChange ->
  UpdateService
newUpdateService :: Text -> ServiceChange -> UpdateService
newUpdateService Text
pId_ ServiceChange
pService_ =
  UpdateService' :: Text -> ServiceChange -> UpdateService
UpdateService' {$sel:id:UpdateService' :: Text
id = Text
pId_, $sel:service:UpdateService' :: ServiceChange
service = ServiceChange
pService_}

-- | The ID of the service that you want to update.
updateService_id :: Lens.Lens' UpdateService Prelude.Text
updateService_id :: (Text -> f Text) -> UpdateService -> f UpdateService
updateService_id = (UpdateService -> Text)
-> (UpdateService -> Text -> UpdateService)
-> Lens UpdateService UpdateService Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateService' {Text
id :: Text
$sel:id:UpdateService' :: UpdateService -> Text
id} -> Text
id) (\s :: UpdateService
s@UpdateService' {} Text
a -> UpdateService
s {$sel:id:UpdateService' :: Text
id = Text
a} :: UpdateService)

-- | A complex type that contains the new settings for the service.
updateService_service :: Lens.Lens' UpdateService ServiceChange
updateService_service :: (ServiceChange -> f ServiceChange)
-> UpdateService -> f UpdateService
updateService_service = (UpdateService -> ServiceChange)
-> (UpdateService -> ServiceChange -> UpdateService)
-> Lens UpdateService UpdateService ServiceChange ServiceChange
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateService' {ServiceChange
service :: ServiceChange
$sel:service:UpdateService' :: UpdateService -> ServiceChange
service} -> ServiceChange
service) (\s :: UpdateService
s@UpdateService' {} ServiceChange
a -> UpdateService
s {$sel:service:UpdateService' :: ServiceChange
service = ServiceChange
a} :: UpdateService)

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

instance Prelude.NFData UpdateService

instance Core.ToHeaders UpdateService where
  toHeaders :: UpdateService -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateService -> 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
"Route53AutoNaming_v20170314.UpdateService" ::
                          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 UpdateService where
  toJSON :: UpdateService -> Value
toJSON UpdateService' {Text
ServiceChange
service :: ServiceChange
id :: Text
$sel:service:UpdateService' :: UpdateService -> ServiceChange
$sel:id:UpdateService' :: UpdateService -> 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
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Service" Text -> ServiceChange -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ServiceChange
service)
          ]
      )

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

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

-- | /See:/ 'newUpdateServiceResponse' smart constructor.
data UpdateServiceResponse = UpdateServiceResponse'
  { -- | A value that you can use to determine whether the request completed
    -- successfully. To get the status of the operation, see
    -- <https://docs.aws.amazon.com/cloud-map/latest/api/API_GetOperation.html GetOperation>.
    UpdateServiceResponse -> Maybe Text
operationId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    UpdateServiceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateServiceResponse -> UpdateServiceResponse -> Bool
(UpdateServiceResponse -> UpdateServiceResponse -> Bool)
-> (UpdateServiceResponse -> UpdateServiceResponse -> Bool)
-> Eq UpdateServiceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateServiceResponse -> UpdateServiceResponse -> Bool
$c/= :: UpdateServiceResponse -> UpdateServiceResponse -> Bool
== :: UpdateServiceResponse -> UpdateServiceResponse -> Bool
$c== :: UpdateServiceResponse -> UpdateServiceResponse -> Bool
Prelude.Eq, ReadPrec [UpdateServiceResponse]
ReadPrec UpdateServiceResponse
Int -> ReadS UpdateServiceResponse
ReadS [UpdateServiceResponse]
(Int -> ReadS UpdateServiceResponse)
-> ReadS [UpdateServiceResponse]
-> ReadPrec UpdateServiceResponse
-> ReadPrec [UpdateServiceResponse]
-> Read UpdateServiceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateServiceResponse]
$creadListPrec :: ReadPrec [UpdateServiceResponse]
readPrec :: ReadPrec UpdateServiceResponse
$creadPrec :: ReadPrec UpdateServiceResponse
readList :: ReadS [UpdateServiceResponse]
$creadList :: ReadS [UpdateServiceResponse]
readsPrec :: Int -> ReadS UpdateServiceResponse
$creadsPrec :: Int -> ReadS UpdateServiceResponse
Prelude.Read, Int -> UpdateServiceResponse -> ShowS
[UpdateServiceResponse] -> ShowS
UpdateServiceResponse -> String
(Int -> UpdateServiceResponse -> ShowS)
-> (UpdateServiceResponse -> String)
-> ([UpdateServiceResponse] -> ShowS)
-> Show UpdateServiceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateServiceResponse] -> ShowS
$cshowList :: [UpdateServiceResponse] -> ShowS
show :: UpdateServiceResponse -> String
$cshow :: UpdateServiceResponse -> String
showsPrec :: Int -> UpdateServiceResponse -> ShowS
$cshowsPrec :: Int -> UpdateServiceResponse -> ShowS
Prelude.Show, (forall x. UpdateServiceResponse -> Rep UpdateServiceResponse x)
-> (forall x. Rep UpdateServiceResponse x -> UpdateServiceResponse)
-> Generic UpdateServiceResponse
forall x. Rep UpdateServiceResponse x -> UpdateServiceResponse
forall x. UpdateServiceResponse -> Rep UpdateServiceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateServiceResponse x -> UpdateServiceResponse
$cfrom :: forall x. UpdateServiceResponse -> Rep UpdateServiceResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateServiceResponse' 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:
--
-- 'operationId', 'updateServiceResponse_operationId' - A value that you can use to determine whether the request completed
-- successfully. To get the status of the operation, see
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_GetOperation.html GetOperation>.
--
-- 'httpStatus', 'updateServiceResponse_httpStatus' - The response's http status code.
newUpdateServiceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateServiceResponse
newUpdateServiceResponse :: Int -> UpdateServiceResponse
newUpdateServiceResponse Int
pHttpStatus_ =
  UpdateServiceResponse' :: Maybe Text -> Int -> UpdateServiceResponse
UpdateServiceResponse'
    { $sel:operationId:UpdateServiceResponse' :: Maybe Text
operationId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateServiceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A value that you can use to determine whether the request completed
-- successfully. To get the status of the operation, see
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_GetOperation.html GetOperation>.
updateServiceResponse_operationId :: Lens.Lens' UpdateServiceResponse (Prelude.Maybe Prelude.Text)
updateServiceResponse_operationId :: (Maybe Text -> f (Maybe Text))
-> UpdateServiceResponse -> f UpdateServiceResponse
updateServiceResponse_operationId = (UpdateServiceResponse -> Maybe Text)
-> (UpdateServiceResponse -> Maybe Text -> UpdateServiceResponse)
-> Lens
     UpdateServiceResponse
     UpdateServiceResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateServiceResponse' {Maybe Text
operationId :: Maybe Text
$sel:operationId:UpdateServiceResponse' :: UpdateServiceResponse -> Maybe Text
operationId} -> Maybe Text
operationId) (\s :: UpdateServiceResponse
s@UpdateServiceResponse' {} Maybe Text
a -> UpdateServiceResponse
s {$sel:operationId:UpdateServiceResponse' :: Maybe Text
operationId = Maybe Text
a} :: UpdateServiceResponse)

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

instance Prelude.NFData UpdateServiceResponse