{-# 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.IoT.DeleteThing
-- 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)
--
-- Deletes the specified thing. Returns successfully with no error if the
-- deletion is successful or you specify a thing that doesn\'t exist.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions DeleteThing>
-- action.
module Amazonka.IoT.DeleteThing
  ( -- * Creating a Request
    DeleteThing (..),
    newDeleteThing,

    -- * Request Lenses
    deleteThing_expectedVersion,
    deleteThing_thingName,

    -- * Destructuring the Response
    DeleteThingResponse (..),
    newDeleteThingResponse,

    -- * Response Lenses
    deleteThingResponse_httpStatus,
  )
where

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

-- | The input for the DeleteThing operation.
--
-- /See:/ 'newDeleteThing' smart constructor.
data DeleteThing = DeleteThing'
  { -- | The expected version of the thing record in the registry. If the version
    -- of the record in the registry does not match the expected version
    -- specified in the request, the @DeleteThing@ request is rejected with a
    -- @VersionConflictException@.
    DeleteThing -> Maybe Integer
expectedVersion :: Prelude.Maybe Prelude.Integer,
    -- | The name of the thing to delete.
    DeleteThing -> Text
thingName :: Prelude.Text
  }
  deriving (DeleteThing -> DeleteThing -> Bool
(DeleteThing -> DeleteThing -> Bool)
-> (DeleteThing -> DeleteThing -> Bool) -> Eq DeleteThing
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteThing -> DeleteThing -> Bool
$c/= :: DeleteThing -> DeleteThing -> Bool
== :: DeleteThing -> DeleteThing -> Bool
$c== :: DeleteThing -> DeleteThing -> Bool
Prelude.Eq, ReadPrec [DeleteThing]
ReadPrec DeleteThing
Int -> ReadS DeleteThing
ReadS [DeleteThing]
(Int -> ReadS DeleteThing)
-> ReadS [DeleteThing]
-> ReadPrec DeleteThing
-> ReadPrec [DeleteThing]
-> Read DeleteThing
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteThing]
$creadListPrec :: ReadPrec [DeleteThing]
readPrec :: ReadPrec DeleteThing
$creadPrec :: ReadPrec DeleteThing
readList :: ReadS [DeleteThing]
$creadList :: ReadS [DeleteThing]
readsPrec :: Int -> ReadS DeleteThing
$creadsPrec :: Int -> ReadS DeleteThing
Prelude.Read, Int -> DeleteThing -> ShowS
[DeleteThing] -> ShowS
DeleteThing -> String
(Int -> DeleteThing -> ShowS)
-> (DeleteThing -> String)
-> ([DeleteThing] -> ShowS)
-> Show DeleteThing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteThing] -> ShowS
$cshowList :: [DeleteThing] -> ShowS
show :: DeleteThing -> String
$cshow :: DeleteThing -> String
showsPrec :: Int -> DeleteThing -> ShowS
$cshowsPrec :: Int -> DeleteThing -> ShowS
Prelude.Show, (forall x. DeleteThing -> Rep DeleteThing x)
-> (forall x. Rep DeleteThing x -> DeleteThing)
-> Generic DeleteThing
forall x. Rep DeleteThing x -> DeleteThing
forall x. DeleteThing -> Rep DeleteThing x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteThing x -> DeleteThing
$cfrom :: forall x. DeleteThing -> Rep DeleteThing x
Prelude.Generic)

-- |
-- Create a value of 'DeleteThing' 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:
--
-- 'expectedVersion', 'deleteThing_expectedVersion' - The expected version of the thing record in the registry. If the version
-- of the record in the registry does not match the expected version
-- specified in the request, the @DeleteThing@ request is rejected with a
-- @VersionConflictException@.
--
-- 'thingName', 'deleteThing_thingName' - The name of the thing to delete.
newDeleteThing ::
  -- | 'thingName'
  Prelude.Text ->
  DeleteThing
newDeleteThing :: Text -> DeleteThing
newDeleteThing Text
pThingName_ =
  DeleteThing' :: Maybe Integer -> Text -> DeleteThing
DeleteThing'
    { $sel:expectedVersion:DeleteThing' :: Maybe Integer
expectedVersion = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:thingName:DeleteThing' :: Text
thingName = Text
pThingName_
    }

-- | The expected version of the thing record in the registry. If the version
-- of the record in the registry does not match the expected version
-- specified in the request, the @DeleteThing@ request is rejected with a
-- @VersionConflictException@.
deleteThing_expectedVersion :: Lens.Lens' DeleteThing (Prelude.Maybe Prelude.Integer)
deleteThing_expectedVersion :: (Maybe Integer -> f (Maybe Integer))
-> DeleteThing -> f DeleteThing
deleteThing_expectedVersion = (DeleteThing -> Maybe Integer)
-> (DeleteThing -> Maybe Integer -> DeleteThing)
-> Lens DeleteThing DeleteThing (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteThing' {Maybe Integer
expectedVersion :: Maybe Integer
$sel:expectedVersion:DeleteThing' :: DeleteThing -> Maybe Integer
expectedVersion} -> Maybe Integer
expectedVersion) (\s :: DeleteThing
s@DeleteThing' {} Maybe Integer
a -> DeleteThing
s {$sel:expectedVersion:DeleteThing' :: Maybe Integer
expectedVersion = Maybe Integer
a} :: DeleteThing)

-- | The name of the thing to delete.
deleteThing_thingName :: Lens.Lens' DeleteThing Prelude.Text
deleteThing_thingName :: (Text -> f Text) -> DeleteThing -> f DeleteThing
deleteThing_thingName = (DeleteThing -> Text)
-> (DeleteThing -> Text -> DeleteThing)
-> Lens DeleteThing DeleteThing Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteThing' {Text
thingName :: Text
$sel:thingName:DeleteThing' :: DeleteThing -> Text
thingName} -> Text
thingName) (\s :: DeleteThing
s@DeleteThing' {} Text
a -> DeleteThing
s {$sel:thingName:DeleteThing' :: Text
thingName = Text
a} :: DeleteThing)

instance Core.AWSRequest DeleteThing where
  type AWSResponse DeleteThing = DeleteThingResponse
  request :: DeleteThing -> Request DeleteThing
request = Service -> DeleteThing -> Request DeleteThing
forall a. ToRequest a => Service -> a -> Request a
Request.delete Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteThing
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteThing)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse DeleteThing))
-> Logger
-> Service
-> Proxy DeleteThing
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteThing)))
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 -> DeleteThingResponse
DeleteThingResponse'
            (Int -> DeleteThingResponse)
-> Either String Int -> Either String DeleteThingResponse
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 DeleteThing

instance Prelude.NFData DeleteThing

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

instance Core.ToPath DeleteThing where
  toPath :: DeleteThing -> ByteString
toPath DeleteThing' {Maybe Integer
Text
thingName :: Text
expectedVersion :: Maybe Integer
$sel:thingName:DeleteThing' :: DeleteThing -> Text
$sel:expectedVersion:DeleteThing' :: DeleteThing -> Maybe Integer
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/things/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
thingName]

instance Core.ToQuery DeleteThing where
  toQuery :: DeleteThing -> QueryString
toQuery DeleteThing' {Maybe Integer
Text
thingName :: Text
expectedVersion :: Maybe Integer
$sel:thingName:DeleteThing' :: DeleteThing -> Text
$sel:expectedVersion:DeleteThing' :: DeleteThing -> Maybe Integer
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"expectedVersion" ByteString -> Maybe Integer -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Integer
expectedVersion]

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

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

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

instance Prelude.NFData DeleteThingResponse