{-# 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.UpdateDeviceState
-- 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)
--
-- Using a Boolean value (true or false), this operation enables or
-- disables the device given a device ID.
module Amazonka.IoT1ClickDevices.UpdateDeviceState
  ( -- * Creating a Request
    UpdateDeviceState (..),
    newUpdateDeviceState,

    -- * Request Lenses
    updateDeviceState_enabled,
    updateDeviceState_deviceId,

    -- * Destructuring the Response
    UpdateDeviceStateResponse (..),
    newUpdateDeviceStateResponse,

    -- * Response Lenses
    updateDeviceStateResponse_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:/ 'newUpdateDeviceState' smart constructor.
data UpdateDeviceState = UpdateDeviceState'
  { -- | If true, the device is enabled. If false, the device is disabled.
    UpdateDeviceState -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | The unique identifier of the device.
    UpdateDeviceState -> Text
deviceId :: Prelude.Text
  }
  deriving (UpdateDeviceState -> UpdateDeviceState -> Bool
(UpdateDeviceState -> UpdateDeviceState -> Bool)
-> (UpdateDeviceState -> UpdateDeviceState -> Bool)
-> Eq UpdateDeviceState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateDeviceState -> UpdateDeviceState -> Bool
$c/= :: UpdateDeviceState -> UpdateDeviceState -> Bool
== :: UpdateDeviceState -> UpdateDeviceState -> Bool
$c== :: UpdateDeviceState -> UpdateDeviceState -> Bool
Prelude.Eq, ReadPrec [UpdateDeviceState]
ReadPrec UpdateDeviceState
Int -> ReadS UpdateDeviceState
ReadS [UpdateDeviceState]
(Int -> ReadS UpdateDeviceState)
-> ReadS [UpdateDeviceState]
-> ReadPrec UpdateDeviceState
-> ReadPrec [UpdateDeviceState]
-> Read UpdateDeviceState
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateDeviceState]
$creadListPrec :: ReadPrec [UpdateDeviceState]
readPrec :: ReadPrec UpdateDeviceState
$creadPrec :: ReadPrec UpdateDeviceState
readList :: ReadS [UpdateDeviceState]
$creadList :: ReadS [UpdateDeviceState]
readsPrec :: Int -> ReadS UpdateDeviceState
$creadsPrec :: Int -> ReadS UpdateDeviceState
Prelude.Read, Int -> UpdateDeviceState -> ShowS
[UpdateDeviceState] -> ShowS
UpdateDeviceState -> String
(Int -> UpdateDeviceState -> ShowS)
-> (UpdateDeviceState -> String)
-> ([UpdateDeviceState] -> ShowS)
-> Show UpdateDeviceState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateDeviceState] -> ShowS
$cshowList :: [UpdateDeviceState] -> ShowS
show :: UpdateDeviceState -> String
$cshow :: UpdateDeviceState -> String
showsPrec :: Int -> UpdateDeviceState -> ShowS
$cshowsPrec :: Int -> UpdateDeviceState -> ShowS
Prelude.Show, (forall x. UpdateDeviceState -> Rep UpdateDeviceState x)
-> (forall x. Rep UpdateDeviceState x -> UpdateDeviceState)
-> Generic UpdateDeviceState
forall x. Rep UpdateDeviceState x -> UpdateDeviceState
forall x. UpdateDeviceState -> Rep UpdateDeviceState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateDeviceState x -> UpdateDeviceState
$cfrom :: forall x. UpdateDeviceState -> Rep UpdateDeviceState x
Prelude.Generic)

-- |
-- Create a value of 'UpdateDeviceState' 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:
--
-- 'enabled', 'updateDeviceState_enabled' - If true, the device is enabled. If false, the device is disabled.
--
-- 'deviceId', 'updateDeviceState_deviceId' - The unique identifier of the device.
newUpdateDeviceState ::
  -- | 'deviceId'
  Prelude.Text ->
  UpdateDeviceState
newUpdateDeviceState :: Text -> UpdateDeviceState
newUpdateDeviceState Text
pDeviceId_ =
  UpdateDeviceState' :: Maybe Bool -> Text -> UpdateDeviceState
UpdateDeviceState'
    { $sel:enabled:UpdateDeviceState' :: Maybe Bool
enabled = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:deviceId:UpdateDeviceState' :: Text
deviceId = Text
pDeviceId_
    }

-- | If true, the device is enabled. If false, the device is disabled.
updateDeviceState_enabled :: Lens.Lens' UpdateDeviceState (Prelude.Maybe Prelude.Bool)
updateDeviceState_enabled :: (Maybe Bool -> f (Maybe Bool))
-> UpdateDeviceState -> f UpdateDeviceState
updateDeviceState_enabled = (UpdateDeviceState -> Maybe Bool)
-> (UpdateDeviceState -> Maybe Bool -> UpdateDeviceState)
-> Lens
     UpdateDeviceState UpdateDeviceState (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateDeviceState' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:UpdateDeviceState' :: UpdateDeviceState -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: UpdateDeviceState
s@UpdateDeviceState' {} Maybe Bool
a -> UpdateDeviceState
s {$sel:enabled:UpdateDeviceState' :: Maybe Bool
enabled = Maybe Bool
a} :: UpdateDeviceState)

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

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

instance Prelude.NFData UpdateDeviceState

instance Core.ToHeaders UpdateDeviceState where
  toHeaders :: UpdateDeviceState -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateDeviceState -> 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 UpdateDeviceState where
  toJSON :: UpdateDeviceState -> Value
toJSON UpdateDeviceState' {Maybe Bool
Text
deviceId :: Text
enabled :: Maybe Bool
$sel:deviceId:UpdateDeviceState' :: UpdateDeviceState -> Text
$sel:enabled:UpdateDeviceState' :: UpdateDeviceState -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"enabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enabled]
      )

instance Core.ToPath UpdateDeviceState where
  toPath :: UpdateDeviceState -> ByteString
toPath UpdateDeviceState' {Maybe Bool
Text
deviceId :: Text
enabled :: Maybe Bool
$sel:deviceId:UpdateDeviceState' :: UpdateDeviceState -> Text
$sel:enabled:UpdateDeviceState' :: UpdateDeviceState -> Maybe Bool
..} =
    [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
"/state"]

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

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

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

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

instance Prelude.NFData UpdateDeviceStateResponse