{-# 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.IoT1ClickDevices.InitiateDeviceClaim
-- 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)
--
-- Given a device ID, initiates a claim request for the associated device.
--
-- Claiming a device consists of initiating a claim, then publishing a
-- device event, and finalizing the claim. For a device of type button, a
-- device event can be published by simply clicking the device.
module Amazonka.IoT1ClickDevices.InitiateDeviceClaim
  ( -- * Creating a Request
    InitiateDeviceClaim (..),
    newInitiateDeviceClaim,

    -- * Request Lenses
    initiateDeviceClaim_deviceId,

    -- * Destructuring the Response
    InitiateDeviceClaimResponse (..),
    newInitiateDeviceClaimResponse,

    -- * Response Lenses
    initiateDeviceClaimResponse_state,
    initiateDeviceClaimResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT1ClickDevices.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

-- | /See:/ 'newInitiateDeviceClaim' smart constructor.
data InitiateDeviceClaim = InitiateDeviceClaim'
  { -- | The unique identifier of the device.
    InitiateDeviceClaim -> Text
deviceId :: Prelude.Text
  }
  deriving (InitiateDeviceClaim -> InitiateDeviceClaim -> Bool
(InitiateDeviceClaim -> InitiateDeviceClaim -> Bool)
-> (InitiateDeviceClaim -> InitiateDeviceClaim -> Bool)
-> Eq InitiateDeviceClaim
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InitiateDeviceClaim -> InitiateDeviceClaim -> Bool
$c/= :: InitiateDeviceClaim -> InitiateDeviceClaim -> Bool
== :: InitiateDeviceClaim -> InitiateDeviceClaim -> Bool
$c== :: InitiateDeviceClaim -> InitiateDeviceClaim -> Bool
Prelude.Eq, ReadPrec [InitiateDeviceClaim]
ReadPrec InitiateDeviceClaim
Int -> ReadS InitiateDeviceClaim
ReadS [InitiateDeviceClaim]
(Int -> ReadS InitiateDeviceClaim)
-> ReadS [InitiateDeviceClaim]
-> ReadPrec InitiateDeviceClaim
-> ReadPrec [InitiateDeviceClaim]
-> Read InitiateDeviceClaim
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InitiateDeviceClaim]
$creadListPrec :: ReadPrec [InitiateDeviceClaim]
readPrec :: ReadPrec InitiateDeviceClaim
$creadPrec :: ReadPrec InitiateDeviceClaim
readList :: ReadS [InitiateDeviceClaim]
$creadList :: ReadS [InitiateDeviceClaim]
readsPrec :: Int -> ReadS InitiateDeviceClaim
$creadsPrec :: Int -> ReadS InitiateDeviceClaim
Prelude.Read, Int -> InitiateDeviceClaim -> ShowS
[InitiateDeviceClaim] -> ShowS
InitiateDeviceClaim -> String
(Int -> InitiateDeviceClaim -> ShowS)
-> (InitiateDeviceClaim -> String)
-> ([InitiateDeviceClaim] -> ShowS)
-> Show InitiateDeviceClaim
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InitiateDeviceClaim] -> ShowS
$cshowList :: [InitiateDeviceClaim] -> ShowS
show :: InitiateDeviceClaim -> String
$cshow :: InitiateDeviceClaim -> String
showsPrec :: Int -> InitiateDeviceClaim -> ShowS
$cshowsPrec :: Int -> InitiateDeviceClaim -> ShowS
Prelude.Show, (forall x. InitiateDeviceClaim -> Rep InitiateDeviceClaim x)
-> (forall x. Rep InitiateDeviceClaim x -> InitiateDeviceClaim)
-> Generic InitiateDeviceClaim
forall x. Rep InitiateDeviceClaim x -> InitiateDeviceClaim
forall x. InitiateDeviceClaim -> Rep InitiateDeviceClaim x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InitiateDeviceClaim x -> InitiateDeviceClaim
$cfrom :: forall x. InitiateDeviceClaim -> Rep InitiateDeviceClaim x
Prelude.Generic)

-- |
-- Create a value of 'InitiateDeviceClaim' 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:
--
-- 'deviceId', 'initiateDeviceClaim_deviceId' - The unique identifier of the device.
newInitiateDeviceClaim ::
  -- | 'deviceId'
  Prelude.Text ->
  InitiateDeviceClaim
newInitiateDeviceClaim :: Text -> InitiateDeviceClaim
newInitiateDeviceClaim Text
pDeviceId_ =
  InitiateDeviceClaim' :: Text -> InitiateDeviceClaim
InitiateDeviceClaim' {$sel:deviceId:InitiateDeviceClaim' :: Text
deviceId = Text
pDeviceId_}

-- | The unique identifier of the device.
initiateDeviceClaim_deviceId :: Lens.Lens' InitiateDeviceClaim Prelude.Text
initiateDeviceClaim_deviceId :: (Text -> f Text) -> InitiateDeviceClaim -> f InitiateDeviceClaim
initiateDeviceClaim_deviceId = (InitiateDeviceClaim -> Text)
-> (InitiateDeviceClaim -> Text -> InitiateDeviceClaim)
-> Lens InitiateDeviceClaim InitiateDeviceClaim Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InitiateDeviceClaim' {Text
deviceId :: Text
$sel:deviceId:InitiateDeviceClaim' :: InitiateDeviceClaim -> Text
deviceId} -> Text
deviceId) (\s :: InitiateDeviceClaim
s@InitiateDeviceClaim' {} Text
a -> InitiateDeviceClaim
s {$sel:deviceId:InitiateDeviceClaim' :: Text
deviceId = Text
a} :: InitiateDeviceClaim)

instance Core.AWSRequest InitiateDeviceClaim where
  type
    AWSResponse InitiateDeviceClaim =
      InitiateDeviceClaimResponse
  request :: InitiateDeviceClaim -> Request InitiateDeviceClaim
request = Service -> InitiateDeviceClaim -> Request InitiateDeviceClaim
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy InitiateDeviceClaim
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse InitiateDeviceClaim)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse InitiateDeviceClaim))
-> Logger
-> Service
-> Proxy InitiateDeviceClaim
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse InitiateDeviceClaim)))
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 -> InitiateDeviceClaimResponse
InitiateDeviceClaimResponse'
            (Maybe Text -> Int -> InitiateDeviceClaimResponse)
-> Either String (Maybe Text)
-> Either String (Int -> InitiateDeviceClaimResponse)
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
"state")
            Either String (Int -> InitiateDeviceClaimResponse)
-> Either String Int -> Either String InitiateDeviceClaimResponse
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 InitiateDeviceClaim

instance Prelude.NFData InitiateDeviceClaim

instance Core.ToHeaders InitiateDeviceClaim where
  toHeaders :: InitiateDeviceClaim -> ResponseHeaders
toHeaders =
    ResponseHeaders -> InitiateDeviceClaim -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 InitiateDeviceClaim where
  toJSON :: InitiateDeviceClaim -> Value
toJSON = Value -> InitiateDeviceClaim -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath InitiateDeviceClaim where
  toPath :: InitiateDeviceClaim -> ByteString
toPath InitiateDeviceClaim' {Text
deviceId :: Text
$sel:deviceId:InitiateDeviceClaim' :: InitiateDeviceClaim -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/devices/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
deviceId, ByteString
"/initiate-claim"]

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

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

-- |
-- Create a value of 'InitiateDeviceClaimResponse' 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:
--
-- 'state', 'initiateDeviceClaimResponse_state' - The device\'s final claim state.
--
-- 'httpStatus', 'initiateDeviceClaimResponse_httpStatus' - The response's http status code.
newInitiateDeviceClaimResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  InitiateDeviceClaimResponse
newInitiateDeviceClaimResponse :: Int -> InitiateDeviceClaimResponse
newInitiateDeviceClaimResponse Int
pHttpStatus_ =
  InitiateDeviceClaimResponse' :: Maybe Text -> Int -> InitiateDeviceClaimResponse
InitiateDeviceClaimResponse'
    { $sel:state:InitiateDeviceClaimResponse' :: Maybe Text
state =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:InitiateDeviceClaimResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The device\'s final claim state.
initiateDeviceClaimResponse_state :: Lens.Lens' InitiateDeviceClaimResponse (Prelude.Maybe Prelude.Text)
initiateDeviceClaimResponse_state :: (Maybe Text -> f (Maybe Text))
-> InitiateDeviceClaimResponse -> f InitiateDeviceClaimResponse
initiateDeviceClaimResponse_state = (InitiateDeviceClaimResponse -> Maybe Text)
-> (InitiateDeviceClaimResponse
    -> Maybe Text -> InitiateDeviceClaimResponse)
-> Lens
     InitiateDeviceClaimResponse
     InitiateDeviceClaimResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InitiateDeviceClaimResponse' {Maybe Text
state :: Maybe Text
$sel:state:InitiateDeviceClaimResponse' :: InitiateDeviceClaimResponse -> Maybe Text
state} -> Maybe Text
state) (\s :: InitiateDeviceClaimResponse
s@InitiateDeviceClaimResponse' {} Maybe Text
a -> InitiateDeviceClaimResponse
s {$sel:state:InitiateDeviceClaimResponse' :: Maybe Text
state = Maybe Text
a} :: InitiateDeviceClaimResponse)

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

instance Prelude.NFData InitiateDeviceClaimResponse