{-# 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.IoTThingsGraph.AssociateEntityToThing
-- 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)
--
-- Associates a device with a concrete thing that is in the user\'s
-- registry.
--
-- A thing can be associated with only one device at a time. If you
-- associate a thing with a new device id, its previous association will be
-- removed.
module Amazonka.IoTThingsGraph.AssociateEntityToThing
  ( -- * Creating a Request
    AssociateEntityToThing (..),
    newAssociateEntityToThing,

    -- * Request Lenses
    associateEntityToThing_namespaceVersion,
    associateEntityToThing_thingName,
    associateEntityToThing_entityId,

    -- * Destructuring the Response
    AssociateEntityToThingResponse (..),
    newAssociateEntityToThingResponse,

    -- * Response Lenses
    associateEntityToThingResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTThingsGraph.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:/ 'newAssociateEntityToThing' smart constructor.
data AssociateEntityToThing = AssociateEntityToThing'
  { -- | The version of the user\'s namespace. Defaults to the latest version of
    -- the user\'s namespace.
    AssociateEntityToThing -> Maybe Integer
namespaceVersion :: Prelude.Maybe Prelude.Integer,
    -- | The name of the thing to which the entity is to be associated.
    AssociateEntityToThing -> Text
thingName :: Prelude.Text,
    -- | The ID of the device to be associated with the thing.
    --
    -- The ID should be in the following format.
    --
    -- @urn:tdm:REGION\/ACCOUNT ID\/default:device:DEVICENAME@
    AssociateEntityToThing -> Text
entityId :: Prelude.Text
  }
  deriving (AssociateEntityToThing -> AssociateEntityToThing -> Bool
(AssociateEntityToThing -> AssociateEntityToThing -> Bool)
-> (AssociateEntityToThing -> AssociateEntityToThing -> Bool)
-> Eq AssociateEntityToThing
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateEntityToThing -> AssociateEntityToThing -> Bool
$c/= :: AssociateEntityToThing -> AssociateEntityToThing -> Bool
== :: AssociateEntityToThing -> AssociateEntityToThing -> Bool
$c== :: AssociateEntityToThing -> AssociateEntityToThing -> Bool
Prelude.Eq, ReadPrec [AssociateEntityToThing]
ReadPrec AssociateEntityToThing
Int -> ReadS AssociateEntityToThing
ReadS [AssociateEntityToThing]
(Int -> ReadS AssociateEntityToThing)
-> ReadS [AssociateEntityToThing]
-> ReadPrec AssociateEntityToThing
-> ReadPrec [AssociateEntityToThing]
-> Read AssociateEntityToThing
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateEntityToThing]
$creadListPrec :: ReadPrec [AssociateEntityToThing]
readPrec :: ReadPrec AssociateEntityToThing
$creadPrec :: ReadPrec AssociateEntityToThing
readList :: ReadS [AssociateEntityToThing]
$creadList :: ReadS [AssociateEntityToThing]
readsPrec :: Int -> ReadS AssociateEntityToThing
$creadsPrec :: Int -> ReadS AssociateEntityToThing
Prelude.Read, Int -> AssociateEntityToThing -> ShowS
[AssociateEntityToThing] -> ShowS
AssociateEntityToThing -> String
(Int -> AssociateEntityToThing -> ShowS)
-> (AssociateEntityToThing -> String)
-> ([AssociateEntityToThing] -> ShowS)
-> Show AssociateEntityToThing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateEntityToThing] -> ShowS
$cshowList :: [AssociateEntityToThing] -> ShowS
show :: AssociateEntityToThing -> String
$cshow :: AssociateEntityToThing -> String
showsPrec :: Int -> AssociateEntityToThing -> ShowS
$cshowsPrec :: Int -> AssociateEntityToThing -> ShowS
Prelude.Show, (forall x. AssociateEntityToThing -> Rep AssociateEntityToThing x)
-> (forall x.
    Rep AssociateEntityToThing x -> AssociateEntityToThing)
-> Generic AssociateEntityToThing
forall x. Rep AssociateEntityToThing x -> AssociateEntityToThing
forall x. AssociateEntityToThing -> Rep AssociateEntityToThing x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateEntityToThing x -> AssociateEntityToThing
$cfrom :: forall x. AssociateEntityToThing -> Rep AssociateEntityToThing x
Prelude.Generic)

-- |
-- Create a value of 'AssociateEntityToThing' 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:
--
-- 'namespaceVersion', 'associateEntityToThing_namespaceVersion' - The version of the user\'s namespace. Defaults to the latest version of
-- the user\'s namespace.
--
-- 'thingName', 'associateEntityToThing_thingName' - The name of the thing to which the entity is to be associated.
--
-- 'entityId', 'associateEntityToThing_entityId' - The ID of the device to be associated with the thing.
--
-- The ID should be in the following format.
--
-- @urn:tdm:REGION\/ACCOUNT ID\/default:device:DEVICENAME@
newAssociateEntityToThing ::
  -- | 'thingName'
  Prelude.Text ->
  -- | 'entityId'
  Prelude.Text ->
  AssociateEntityToThing
newAssociateEntityToThing :: Text -> Text -> AssociateEntityToThing
newAssociateEntityToThing Text
pThingName_ Text
pEntityId_ =
  AssociateEntityToThing' :: Maybe Integer -> Text -> Text -> AssociateEntityToThing
AssociateEntityToThing'
    { $sel:namespaceVersion:AssociateEntityToThing' :: Maybe Integer
namespaceVersion =
        Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:thingName:AssociateEntityToThing' :: Text
thingName = Text
pThingName_,
      $sel:entityId:AssociateEntityToThing' :: Text
entityId = Text
pEntityId_
    }

-- | The version of the user\'s namespace. Defaults to the latest version of
-- the user\'s namespace.
associateEntityToThing_namespaceVersion :: Lens.Lens' AssociateEntityToThing (Prelude.Maybe Prelude.Integer)
associateEntityToThing_namespaceVersion :: (Maybe Integer -> f (Maybe Integer))
-> AssociateEntityToThing -> f AssociateEntityToThing
associateEntityToThing_namespaceVersion = (AssociateEntityToThing -> Maybe Integer)
-> (AssociateEntityToThing
    -> Maybe Integer -> AssociateEntityToThing)
-> Lens
     AssociateEntityToThing
     AssociateEntityToThing
     (Maybe Integer)
     (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEntityToThing' {Maybe Integer
namespaceVersion :: Maybe Integer
$sel:namespaceVersion:AssociateEntityToThing' :: AssociateEntityToThing -> Maybe Integer
namespaceVersion} -> Maybe Integer
namespaceVersion) (\s :: AssociateEntityToThing
s@AssociateEntityToThing' {} Maybe Integer
a -> AssociateEntityToThing
s {$sel:namespaceVersion:AssociateEntityToThing' :: Maybe Integer
namespaceVersion = Maybe Integer
a} :: AssociateEntityToThing)

-- | The name of the thing to which the entity is to be associated.
associateEntityToThing_thingName :: Lens.Lens' AssociateEntityToThing Prelude.Text
associateEntityToThing_thingName :: (Text -> f Text)
-> AssociateEntityToThing -> f AssociateEntityToThing
associateEntityToThing_thingName = (AssociateEntityToThing -> Text)
-> (AssociateEntityToThing -> Text -> AssociateEntityToThing)
-> Lens AssociateEntityToThing AssociateEntityToThing Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEntityToThing' {Text
thingName :: Text
$sel:thingName:AssociateEntityToThing' :: AssociateEntityToThing -> Text
thingName} -> Text
thingName) (\s :: AssociateEntityToThing
s@AssociateEntityToThing' {} Text
a -> AssociateEntityToThing
s {$sel:thingName:AssociateEntityToThing' :: Text
thingName = Text
a} :: AssociateEntityToThing)

-- | The ID of the device to be associated with the thing.
--
-- The ID should be in the following format.
--
-- @urn:tdm:REGION\/ACCOUNT ID\/default:device:DEVICENAME@
associateEntityToThing_entityId :: Lens.Lens' AssociateEntityToThing Prelude.Text
associateEntityToThing_entityId :: (Text -> f Text)
-> AssociateEntityToThing -> f AssociateEntityToThing
associateEntityToThing_entityId = (AssociateEntityToThing -> Text)
-> (AssociateEntityToThing -> Text -> AssociateEntityToThing)
-> Lens AssociateEntityToThing AssociateEntityToThing Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEntityToThing' {Text
entityId :: Text
$sel:entityId:AssociateEntityToThing' :: AssociateEntityToThing -> Text
entityId} -> Text
entityId) (\s :: AssociateEntityToThing
s@AssociateEntityToThing' {} Text
a -> AssociateEntityToThing
s {$sel:entityId:AssociateEntityToThing' :: Text
entityId = Text
a} :: AssociateEntityToThing)

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

instance Prelude.NFData AssociateEntityToThing

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

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

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

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

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

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

instance
  Prelude.NFData
    AssociateEntityToThingResponse