{-# 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.GetEntities
-- 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)
--
-- Gets definitions of the specified entities. Uses the latest version of
-- the user\'s namespace by default. This API returns the following TDM
-- entities.
--
-- -   Properties
--
-- -   States
--
-- -   Events
--
-- -   Actions
--
-- -   Capabilities
--
-- -   Mappings
--
-- -   Devices
--
-- -   Device Models
--
-- -   Services
--
-- This action doesn\'t return definitions for systems, flows, and
-- deployments.
module Amazonka.IoTThingsGraph.GetEntities
  ( -- * Creating a Request
    GetEntities (..),
    newGetEntities,

    -- * Request Lenses
    getEntities_namespaceVersion,
    getEntities_ids,

    -- * Destructuring the Response
    GetEntitiesResponse (..),
    newGetEntitiesResponse,

    -- * Response Lenses
    getEntitiesResponse_descriptions,
    getEntitiesResponse_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:/ 'newGetEntities' smart constructor.
data GetEntities = GetEntities'
  { -- | The version of the user\'s namespace. Defaults to the latest version of
    -- the user\'s namespace.
    GetEntities -> Maybe Integer
namespaceVersion :: Prelude.Maybe Prelude.Integer,
    -- | An array of entity IDs.
    --
    -- The IDs should be in the following format.
    --
    -- @urn:tdm:REGION\/ACCOUNT ID\/default:device:DEVICENAME@
    GetEntities -> [Text]
ids :: [Prelude.Text]
  }
  deriving (GetEntities -> GetEntities -> Bool
(GetEntities -> GetEntities -> Bool)
-> (GetEntities -> GetEntities -> Bool) -> Eq GetEntities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEntities -> GetEntities -> Bool
$c/= :: GetEntities -> GetEntities -> Bool
== :: GetEntities -> GetEntities -> Bool
$c== :: GetEntities -> GetEntities -> Bool
Prelude.Eq, ReadPrec [GetEntities]
ReadPrec GetEntities
Int -> ReadS GetEntities
ReadS [GetEntities]
(Int -> ReadS GetEntities)
-> ReadS [GetEntities]
-> ReadPrec GetEntities
-> ReadPrec [GetEntities]
-> Read GetEntities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEntities]
$creadListPrec :: ReadPrec [GetEntities]
readPrec :: ReadPrec GetEntities
$creadPrec :: ReadPrec GetEntities
readList :: ReadS [GetEntities]
$creadList :: ReadS [GetEntities]
readsPrec :: Int -> ReadS GetEntities
$creadsPrec :: Int -> ReadS GetEntities
Prelude.Read, Int -> GetEntities -> ShowS
[GetEntities] -> ShowS
GetEntities -> String
(Int -> GetEntities -> ShowS)
-> (GetEntities -> String)
-> ([GetEntities] -> ShowS)
-> Show GetEntities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEntities] -> ShowS
$cshowList :: [GetEntities] -> ShowS
show :: GetEntities -> String
$cshow :: GetEntities -> String
showsPrec :: Int -> GetEntities -> ShowS
$cshowsPrec :: Int -> GetEntities -> ShowS
Prelude.Show, (forall x. GetEntities -> Rep GetEntities x)
-> (forall x. Rep GetEntities x -> GetEntities)
-> Generic GetEntities
forall x. Rep GetEntities x -> GetEntities
forall x. GetEntities -> Rep GetEntities x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetEntities x -> GetEntities
$cfrom :: forall x. GetEntities -> Rep GetEntities x
Prelude.Generic)

-- |
-- Create a value of 'GetEntities' 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', 'getEntities_namespaceVersion' - The version of the user\'s namespace. Defaults to the latest version of
-- the user\'s namespace.
--
-- 'ids', 'getEntities_ids' - An array of entity IDs.
--
-- The IDs should be in the following format.
--
-- @urn:tdm:REGION\/ACCOUNT ID\/default:device:DEVICENAME@
newGetEntities ::
  GetEntities
newGetEntities :: GetEntities
newGetEntities =
  GetEntities' :: Maybe Integer -> [Text] -> GetEntities
GetEntities'
    { $sel:namespaceVersion:GetEntities' :: Maybe Integer
namespaceVersion = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:ids:GetEntities' :: [Text]
ids = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

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

-- | An array of entity IDs.
--
-- The IDs should be in the following format.
--
-- @urn:tdm:REGION\/ACCOUNT ID\/default:device:DEVICENAME@
getEntities_ids :: Lens.Lens' GetEntities [Prelude.Text]
getEntities_ids :: ([Text] -> f [Text]) -> GetEntities -> f GetEntities
getEntities_ids = (GetEntities -> [Text])
-> (GetEntities -> [Text] -> GetEntities)
-> Lens GetEntities GetEntities [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEntities' {[Text]
ids :: [Text]
$sel:ids:GetEntities' :: GetEntities -> [Text]
ids} -> [Text]
ids) (\s :: GetEntities
s@GetEntities' {} [Text]
a -> GetEntities
s {$sel:ids:GetEntities' :: [Text]
ids = [Text]
a} :: GetEntities) (([Text] -> f [Text]) -> GetEntities -> f GetEntities)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GetEntities
-> f GetEntities
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest GetEntities where
  type AWSResponse GetEntities = GetEntitiesResponse
  request :: GetEntities -> Request GetEntities
request = Service -> GetEntities -> Request GetEntities
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetEntities
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetEntities)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetEntities))
-> Logger
-> Service
-> Proxy GetEntities
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetEntities)))
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 [EntityDescription] -> Int -> GetEntitiesResponse
GetEntitiesResponse'
            (Maybe [EntityDescription] -> Int -> GetEntitiesResponse)
-> Either String (Maybe [EntityDescription])
-> Either String (Int -> GetEntitiesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [EntityDescription]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"descriptions" Either String (Maybe (Maybe [EntityDescription]))
-> Maybe [EntityDescription]
-> Either String (Maybe [EntityDescription])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [EntityDescription]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> GetEntitiesResponse)
-> Either String Int -> Either String GetEntitiesResponse
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 GetEntities

instance Prelude.NFData GetEntities

instance Core.ToHeaders GetEntities where
  toHeaders :: GetEntities -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetEntities -> 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.GetEntities" ::
                          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 GetEntities where
  toJSON :: GetEntities -> Value
toJSON GetEntities' {[Text]
Maybe Integer
ids :: [Text]
namespaceVersion :: Maybe Integer
$sel:ids:GetEntities' :: GetEntities -> [Text]
$sel:namespaceVersion:GetEntities' :: GetEntities -> 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
"ids" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
ids)
          ]
      )

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

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

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

-- |
-- Create a value of 'GetEntitiesResponse' 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:
--
-- 'descriptions', 'getEntitiesResponse_descriptions' - An array of descriptions for the specified entities.
--
-- 'httpStatus', 'getEntitiesResponse_httpStatus' - The response's http status code.
newGetEntitiesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetEntitiesResponse
newGetEntitiesResponse :: Int -> GetEntitiesResponse
newGetEntitiesResponse Int
pHttpStatus_ =
  GetEntitiesResponse' :: Maybe [EntityDescription] -> Int -> GetEntitiesResponse
GetEntitiesResponse'
    { $sel:descriptions:GetEntitiesResponse' :: Maybe [EntityDescription]
descriptions =
        Maybe [EntityDescription]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetEntitiesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of descriptions for the specified entities.
getEntitiesResponse_descriptions :: Lens.Lens' GetEntitiesResponse (Prelude.Maybe [EntityDescription])
getEntitiesResponse_descriptions :: (Maybe [EntityDescription] -> f (Maybe [EntityDescription]))
-> GetEntitiesResponse -> f GetEntitiesResponse
getEntitiesResponse_descriptions = (GetEntitiesResponse -> Maybe [EntityDescription])
-> (GetEntitiesResponse
    -> Maybe [EntityDescription] -> GetEntitiesResponse)
-> Lens
     GetEntitiesResponse
     GetEntitiesResponse
     (Maybe [EntityDescription])
     (Maybe [EntityDescription])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEntitiesResponse' {Maybe [EntityDescription]
descriptions :: Maybe [EntityDescription]
$sel:descriptions:GetEntitiesResponse' :: GetEntitiesResponse -> Maybe [EntityDescription]
descriptions} -> Maybe [EntityDescription]
descriptions) (\s :: GetEntitiesResponse
s@GetEntitiesResponse' {} Maybe [EntityDescription]
a -> GetEntitiesResponse
s {$sel:descriptions:GetEntitiesResponse' :: Maybe [EntityDescription]
descriptions = Maybe [EntityDescription]
a} :: GetEntitiesResponse) ((Maybe [EntityDescription] -> f (Maybe [EntityDescription]))
 -> GetEntitiesResponse -> f GetEntitiesResponse)
-> ((Maybe [EntityDescription] -> f (Maybe [EntityDescription]))
    -> Maybe [EntityDescription] -> f (Maybe [EntityDescription]))
-> (Maybe [EntityDescription] -> f (Maybe [EntityDescription]))
-> GetEntitiesResponse
-> f GetEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [EntityDescription]
  [EntityDescription]
  [EntityDescription]
  [EntityDescription]
-> Iso
     (Maybe [EntityDescription])
     (Maybe [EntityDescription])
     (Maybe [EntityDescription])
     (Maybe [EntityDescription])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [EntityDescription]
  [EntityDescription]
  [EntityDescription]
  [EntityDescription]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetEntitiesResponse