{-# 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.SSM.DeregisterManagedInstance
-- 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)
--
-- Removes the server or virtual machine from the list of registered
-- servers. You can reregister the instance again at any time. If you
-- don\'t plan to use Run Command on the server, we suggest uninstalling
-- SSM Agent first.
module Amazonka.SSM.DeregisterManagedInstance
  ( -- * Creating a Request
    DeregisterManagedInstance (..),
    newDeregisterManagedInstance,

    -- * Request Lenses
    deregisterManagedInstance_instanceId,

    -- * Destructuring the Response
    DeregisterManagedInstanceResponse (..),
    newDeregisterManagedInstanceResponse,

    -- * Response Lenses
    deregisterManagedInstanceResponse_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.SSM.Types

-- | /See:/ 'newDeregisterManagedInstance' smart constructor.
data DeregisterManagedInstance = DeregisterManagedInstance'
  { -- | The ID assigned to the managed instance when you registered it using the
    -- activation process.
    DeregisterManagedInstance -> Text
instanceId :: Prelude.Text
  }
  deriving (DeregisterManagedInstance -> DeregisterManagedInstance -> Bool
(DeregisterManagedInstance -> DeregisterManagedInstance -> Bool)
-> (DeregisterManagedInstance -> DeregisterManagedInstance -> Bool)
-> Eq DeregisterManagedInstance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeregisterManagedInstance -> DeregisterManagedInstance -> Bool
$c/= :: DeregisterManagedInstance -> DeregisterManagedInstance -> Bool
== :: DeregisterManagedInstance -> DeregisterManagedInstance -> Bool
$c== :: DeregisterManagedInstance -> DeregisterManagedInstance -> Bool
Prelude.Eq, ReadPrec [DeregisterManagedInstance]
ReadPrec DeregisterManagedInstance
Int -> ReadS DeregisterManagedInstance
ReadS [DeregisterManagedInstance]
(Int -> ReadS DeregisterManagedInstance)
-> ReadS [DeregisterManagedInstance]
-> ReadPrec DeregisterManagedInstance
-> ReadPrec [DeregisterManagedInstance]
-> Read DeregisterManagedInstance
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeregisterManagedInstance]
$creadListPrec :: ReadPrec [DeregisterManagedInstance]
readPrec :: ReadPrec DeregisterManagedInstance
$creadPrec :: ReadPrec DeregisterManagedInstance
readList :: ReadS [DeregisterManagedInstance]
$creadList :: ReadS [DeregisterManagedInstance]
readsPrec :: Int -> ReadS DeregisterManagedInstance
$creadsPrec :: Int -> ReadS DeregisterManagedInstance
Prelude.Read, Int -> DeregisterManagedInstance -> ShowS
[DeregisterManagedInstance] -> ShowS
DeregisterManagedInstance -> String
(Int -> DeregisterManagedInstance -> ShowS)
-> (DeregisterManagedInstance -> String)
-> ([DeregisterManagedInstance] -> ShowS)
-> Show DeregisterManagedInstance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeregisterManagedInstance] -> ShowS
$cshowList :: [DeregisterManagedInstance] -> ShowS
show :: DeregisterManagedInstance -> String
$cshow :: DeregisterManagedInstance -> String
showsPrec :: Int -> DeregisterManagedInstance -> ShowS
$cshowsPrec :: Int -> DeregisterManagedInstance -> ShowS
Prelude.Show, (forall x.
 DeregisterManagedInstance -> Rep DeregisterManagedInstance x)
-> (forall x.
    Rep DeregisterManagedInstance x -> DeregisterManagedInstance)
-> Generic DeregisterManagedInstance
forall x.
Rep DeregisterManagedInstance x -> DeregisterManagedInstance
forall x.
DeregisterManagedInstance -> Rep DeregisterManagedInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeregisterManagedInstance x -> DeregisterManagedInstance
$cfrom :: forall x.
DeregisterManagedInstance -> Rep DeregisterManagedInstance x
Prelude.Generic)

-- |
-- Create a value of 'DeregisterManagedInstance' 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:
--
-- 'instanceId', 'deregisterManagedInstance_instanceId' - The ID assigned to the managed instance when you registered it using the
-- activation process.
newDeregisterManagedInstance ::
  -- | 'instanceId'
  Prelude.Text ->
  DeregisterManagedInstance
newDeregisterManagedInstance :: Text -> DeregisterManagedInstance
newDeregisterManagedInstance Text
pInstanceId_ =
  DeregisterManagedInstance' :: Text -> DeregisterManagedInstance
DeregisterManagedInstance'
    { $sel:instanceId:DeregisterManagedInstance' :: Text
instanceId =
        Text
pInstanceId_
    }

-- | The ID assigned to the managed instance when you registered it using the
-- activation process.
deregisterManagedInstance_instanceId :: Lens.Lens' DeregisterManagedInstance Prelude.Text
deregisterManagedInstance_instanceId :: (Text -> f Text)
-> DeregisterManagedInstance -> f DeregisterManagedInstance
deregisterManagedInstance_instanceId = (DeregisterManagedInstance -> Text)
-> (DeregisterManagedInstance -> Text -> DeregisterManagedInstance)
-> Lens
     DeregisterManagedInstance DeregisterManagedInstance Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeregisterManagedInstance' {Text
instanceId :: Text
$sel:instanceId:DeregisterManagedInstance' :: DeregisterManagedInstance -> Text
instanceId} -> Text
instanceId) (\s :: DeregisterManagedInstance
s@DeregisterManagedInstance' {} Text
a -> DeregisterManagedInstance
s {$sel:instanceId:DeregisterManagedInstance' :: Text
instanceId = Text
a} :: DeregisterManagedInstance)

instance Core.AWSRequest DeregisterManagedInstance where
  type
    AWSResponse DeregisterManagedInstance =
      DeregisterManagedInstanceResponse
  request :: DeregisterManagedInstance -> Request DeregisterManagedInstance
request = Service
-> DeregisterManagedInstance -> Request DeregisterManagedInstance
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeregisterManagedInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeregisterManagedInstance)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse DeregisterManagedInstance))
-> Logger
-> Service
-> Proxy DeregisterManagedInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeregisterManagedInstance)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> DeregisterManagedInstanceResponse
DeregisterManagedInstanceResponse'
            (Int -> DeregisterManagedInstanceResponse)
-> Either String Int
-> Either String DeregisterManagedInstanceResponse
forall (f :: * -> *) a b. Functor 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 DeregisterManagedInstance

instance Prelude.NFData DeregisterManagedInstance

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

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

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

-- | /See:/ 'newDeregisterManagedInstanceResponse' smart constructor.
data DeregisterManagedInstanceResponse = DeregisterManagedInstanceResponse'
  { -- | The response's http status code.
    DeregisterManagedInstanceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeregisterManagedInstanceResponse
-> DeregisterManagedInstanceResponse -> Bool
(DeregisterManagedInstanceResponse
 -> DeregisterManagedInstanceResponse -> Bool)
-> (DeregisterManagedInstanceResponse
    -> DeregisterManagedInstanceResponse -> Bool)
-> Eq DeregisterManagedInstanceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeregisterManagedInstanceResponse
-> DeregisterManagedInstanceResponse -> Bool
$c/= :: DeregisterManagedInstanceResponse
-> DeregisterManagedInstanceResponse -> Bool
== :: DeregisterManagedInstanceResponse
-> DeregisterManagedInstanceResponse -> Bool
$c== :: DeregisterManagedInstanceResponse
-> DeregisterManagedInstanceResponse -> Bool
Prelude.Eq, ReadPrec [DeregisterManagedInstanceResponse]
ReadPrec DeregisterManagedInstanceResponse
Int -> ReadS DeregisterManagedInstanceResponse
ReadS [DeregisterManagedInstanceResponse]
(Int -> ReadS DeregisterManagedInstanceResponse)
-> ReadS [DeregisterManagedInstanceResponse]
-> ReadPrec DeregisterManagedInstanceResponse
-> ReadPrec [DeregisterManagedInstanceResponse]
-> Read DeregisterManagedInstanceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeregisterManagedInstanceResponse]
$creadListPrec :: ReadPrec [DeregisterManagedInstanceResponse]
readPrec :: ReadPrec DeregisterManagedInstanceResponse
$creadPrec :: ReadPrec DeregisterManagedInstanceResponse
readList :: ReadS [DeregisterManagedInstanceResponse]
$creadList :: ReadS [DeregisterManagedInstanceResponse]
readsPrec :: Int -> ReadS DeregisterManagedInstanceResponse
$creadsPrec :: Int -> ReadS DeregisterManagedInstanceResponse
Prelude.Read, Int -> DeregisterManagedInstanceResponse -> ShowS
[DeregisterManagedInstanceResponse] -> ShowS
DeregisterManagedInstanceResponse -> String
(Int -> DeregisterManagedInstanceResponse -> ShowS)
-> (DeregisterManagedInstanceResponse -> String)
-> ([DeregisterManagedInstanceResponse] -> ShowS)
-> Show DeregisterManagedInstanceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeregisterManagedInstanceResponse] -> ShowS
$cshowList :: [DeregisterManagedInstanceResponse] -> ShowS
show :: DeregisterManagedInstanceResponse -> String
$cshow :: DeregisterManagedInstanceResponse -> String
showsPrec :: Int -> DeregisterManagedInstanceResponse -> ShowS
$cshowsPrec :: Int -> DeregisterManagedInstanceResponse -> ShowS
Prelude.Show, (forall x.
 DeregisterManagedInstanceResponse
 -> Rep DeregisterManagedInstanceResponse x)
-> (forall x.
    Rep DeregisterManagedInstanceResponse x
    -> DeregisterManagedInstanceResponse)
-> Generic DeregisterManagedInstanceResponse
forall x.
Rep DeregisterManagedInstanceResponse x
-> DeregisterManagedInstanceResponse
forall x.
DeregisterManagedInstanceResponse
-> Rep DeregisterManagedInstanceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeregisterManagedInstanceResponse x
-> DeregisterManagedInstanceResponse
$cfrom :: forall x.
DeregisterManagedInstanceResponse
-> Rep DeregisterManagedInstanceResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeregisterManagedInstanceResponse' 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:
--
-- 'httpStatus', 'deregisterManagedInstanceResponse_httpStatus' - The response's http status code.
newDeregisterManagedInstanceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeregisterManagedInstanceResponse
newDeregisterManagedInstanceResponse :: Int -> DeregisterManagedInstanceResponse
newDeregisterManagedInstanceResponse Int
pHttpStatus_ =
  DeregisterManagedInstanceResponse' :: Int -> DeregisterManagedInstanceResponse
DeregisterManagedInstanceResponse'
    { $sel:httpStatus:DeregisterManagedInstanceResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance
  Prelude.NFData
    DeregisterManagedInstanceResponse