{-# 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.CognitoSync.DescribeIdentityUsage
-- 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 usage information for an identity, including number of datasets and
-- data usage.
--
-- This API can be called with temporary user credentials provided by
-- Cognito Identity or with developer credentials.
module Amazonka.CognitoSync.DescribeIdentityUsage
  ( -- * Creating a Request
    DescribeIdentityUsage (..),
    newDescribeIdentityUsage,

    -- * Request Lenses
    describeIdentityUsage_identityPoolId,
    describeIdentityUsage_identityId,

    -- * Destructuring the Response
    DescribeIdentityUsageResponse (..),
    newDescribeIdentityUsageResponse,

    -- * Response Lenses
    describeIdentityUsageResponse_identityUsage,
    describeIdentityUsageResponse_httpStatus,
  )
where

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

-- | A request for information about the usage of an identity pool.
--
-- /See:/ 'newDescribeIdentityUsage' smart constructor.
data DescribeIdentityUsage = DescribeIdentityUsage'
  { -- | A name-spaced GUID (for example,
    -- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
    -- Cognito. GUID generation is unique within a region.
    DescribeIdentityUsage -> Text
identityPoolId :: Prelude.Text,
    -- | A name-spaced GUID (for example,
    -- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
    -- Cognito. GUID generation is unique within a region.
    DescribeIdentityUsage -> Text
identityId :: Prelude.Text
  }
  deriving (DescribeIdentityUsage -> DescribeIdentityUsage -> Bool
(DescribeIdentityUsage -> DescribeIdentityUsage -> Bool)
-> (DescribeIdentityUsage -> DescribeIdentityUsage -> Bool)
-> Eq DescribeIdentityUsage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeIdentityUsage -> DescribeIdentityUsage -> Bool
$c/= :: DescribeIdentityUsage -> DescribeIdentityUsage -> Bool
== :: DescribeIdentityUsage -> DescribeIdentityUsage -> Bool
$c== :: DescribeIdentityUsage -> DescribeIdentityUsage -> Bool
Prelude.Eq, ReadPrec [DescribeIdentityUsage]
ReadPrec DescribeIdentityUsage
Int -> ReadS DescribeIdentityUsage
ReadS [DescribeIdentityUsage]
(Int -> ReadS DescribeIdentityUsage)
-> ReadS [DescribeIdentityUsage]
-> ReadPrec DescribeIdentityUsage
-> ReadPrec [DescribeIdentityUsage]
-> Read DescribeIdentityUsage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeIdentityUsage]
$creadListPrec :: ReadPrec [DescribeIdentityUsage]
readPrec :: ReadPrec DescribeIdentityUsage
$creadPrec :: ReadPrec DescribeIdentityUsage
readList :: ReadS [DescribeIdentityUsage]
$creadList :: ReadS [DescribeIdentityUsage]
readsPrec :: Int -> ReadS DescribeIdentityUsage
$creadsPrec :: Int -> ReadS DescribeIdentityUsage
Prelude.Read, Int -> DescribeIdentityUsage -> ShowS
[DescribeIdentityUsage] -> ShowS
DescribeIdentityUsage -> String
(Int -> DescribeIdentityUsage -> ShowS)
-> (DescribeIdentityUsage -> String)
-> ([DescribeIdentityUsage] -> ShowS)
-> Show DescribeIdentityUsage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeIdentityUsage] -> ShowS
$cshowList :: [DescribeIdentityUsage] -> ShowS
show :: DescribeIdentityUsage -> String
$cshow :: DescribeIdentityUsage -> String
showsPrec :: Int -> DescribeIdentityUsage -> ShowS
$cshowsPrec :: Int -> DescribeIdentityUsage -> ShowS
Prelude.Show, (forall x. DescribeIdentityUsage -> Rep DescribeIdentityUsage x)
-> (forall x. Rep DescribeIdentityUsage x -> DescribeIdentityUsage)
-> Generic DescribeIdentityUsage
forall x. Rep DescribeIdentityUsage x -> DescribeIdentityUsage
forall x. DescribeIdentityUsage -> Rep DescribeIdentityUsage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeIdentityUsage x -> DescribeIdentityUsage
$cfrom :: forall x. DescribeIdentityUsage -> Rep DescribeIdentityUsage x
Prelude.Generic)

-- |
-- Create a value of 'DescribeIdentityUsage' 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:
--
-- 'identityPoolId', 'describeIdentityUsage_identityPoolId' - A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
--
-- 'identityId', 'describeIdentityUsage_identityId' - A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
newDescribeIdentityUsage ::
  -- | 'identityPoolId'
  Prelude.Text ->
  -- | 'identityId'
  Prelude.Text ->
  DescribeIdentityUsage
newDescribeIdentityUsage :: Text -> Text -> DescribeIdentityUsage
newDescribeIdentityUsage
  Text
pIdentityPoolId_
  Text
pIdentityId_ =
    DescribeIdentityUsage' :: Text -> Text -> DescribeIdentityUsage
DescribeIdentityUsage'
      { $sel:identityPoolId:DescribeIdentityUsage' :: Text
identityPoolId =
          Text
pIdentityPoolId_,
        $sel:identityId:DescribeIdentityUsage' :: Text
identityId = Text
pIdentityId_
      }

-- | A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
describeIdentityUsage_identityPoolId :: Lens.Lens' DescribeIdentityUsage Prelude.Text
describeIdentityUsage_identityPoolId :: (Text -> f Text)
-> DescribeIdentityUsage -> f DescribeIdentityUsage
describeIdentityUsage_identityPoolId = (DescribeIdentityUsage -> Text)
-> (DescribeIdentityUsage -> Text -> DescribeIdentityUsage)
-> Lens DescribeIdentityUsage DescribeIdentityUsage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeIdentityUsage' {Text
identityPoolId :: Text
$sel:identityPoolId:DescribeIdentityUsage' :: DescribeIdentityUsage -> Text
identityPoolId} -> Text
identityPoolId) (\s :: DescribeIdentityUsage
s@DescribeIdentityUsage' {} Text
a -> DescribeIdentityUsage
s {$sel:identityPoolId:DescribeIdentityUsage' :: Text
identityPoolId = Text
a} :: DescribeIdentityUsage)

-- | A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
describeIdentityUsage_identityId :: Lens.Lens' DescribeIdentityUsage Prelude.Text
describeIdentityUsage_identityId :: (Text -> f Text)
-> DescribeIdentityUsage -> f DescribeIdentityUsage
describeIdentityUsage_identityId = (DescribeIdentityUsage -> Text)
-> (DescribeIdentityUsage -> Text -> DescribeIdentityUsage)
-> Lens DescribeIdentityUsage DescribeIdentityUsage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeIdentityUsage' {Text
identityId :: Text
$sel:identityId:DescribeIdentityUsage' :: DescribeIdentityUsage -> Text
identityId} -> Text
identityId) (\s :: DescribeIdentityUsage
s@DescribeIdentityUsage' {} Text
a -> DescribeIdentityUsage
s {$sel:identityId:DescribeIdentityUsage' :: Text
identityId = Text
a} :: DescribeIdentityUsage)

instance Core.AWSRequest DescribeIdentityUsage where
  type
    AWSResponse DescribeIdentityUsage =
      DescribeIdentityUsageResponse
  request :: DescribeIdentityUsage -> Request DescribeIdentityUsage
request = Service -> DescribeIdentityUsage -> Request DescribeIdentityUsage
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeIdentityUsage
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeIdentityUsage)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeIdentityUsage))
-> Logger
-> Service
-> Proxy DescribeIdentityUsage
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeIdentityUsage)))
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 IdentityUsage -> Int -> DescribeIdentityUsageResponse
DescribeIdentityUsageResponse'
            (Maybe IdentityUsage -> Int -> DescribeIdentityUsageResponse)
-> Either String (Maybe IdentityUsage)
-> Either String (Int -> DescribeIdentityUsageResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe IdentityUsage)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"IdentityUsage")
            Either String (Int -> DescribeIdentityUsageResponse)
-> Either String Int -> Either String DescribeIdentityUsageResponse
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 DescribeIdentityUsage

instance Prelude.NFData DescribeIdentityUsage

instance Core.ToHeaders DescribeIdentityUsage where
  toHeaders :: DescribeIdentityUsage -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeIdentityUsage -> 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.ToPath DescribeIdentityUsage where
  toPath :: DescribeIdentityUsage -> ByteString
toPath DescribeIdentityUsage' {Text
identityId :: Text
identityPoolId :: Text
$sel:identityId:DescribeIdentityUsage' :: DescribeIdentityUsage -> Text
$sel:identityPoolId:DescribeIdentityUsage' :: DescribeIdentityUsage -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/identitypools/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
identityPoolId,
        ByteString
"/identities/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
identityId
      ]

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

-- | The response to a successful DescribeIdentityUsage request.
--
-- /See:/ 'newDescribeIdentityUsageResponse' smart constructor.
data DescribeIdentityUsageResponse = DescribeIdentityUsageResponse'
  { -- | Usage information for the identity.
    DescribeIdentityUsageResponse -> Maybe IdentityUsage
identityUsage :: Prelude.Maybe IdentityUsage,
    -- | The response's http status code.
    DescribeIdentityUsageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeIdentityUsageResponse
-> DescribeIdentityUsageResponse -> Bool
(DescribeIdentityUsageResponse
 -> DescribeIdentityUsageResponse -> Bool)
-> (DescribeIdentityUsageResponse
    -> DescribeIdentityUsageResponse -> Bool)
-> Eq DescribeIdentityUsageResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeIdentityUsageResponse
-> DescribeIdentityUsageResponse -> Bool
$c/= :: DescribeIdentityUsageResponse
-> DescribeIdentityUsageResponse -> Bool
== :: DescribeIdentityUsageResponse
-> DescribeIdentityUsageResponse -> Bool
$c== :: DescribeIdentityUsageResponse
-> DescribeIdentityUsageResponse -> Bool
Prelude.Eq, ReadPrec [DescribeIdentityUsageResponse]
ReadPrec DescribeIdentityUsageResponse
Int -> ReadS DescribeIdentityUsageResponse
ReadS [DescribeIdentityUsageResponse]
(Int -> ReadS DescribeIdentityUsageResponse)
-> ReadS [DescribeIdentityUsageResponse]
-> ReadPrec DescribeIdentityUsageResponse
-> ReadPrec [DescribeIdentityUsageResponse]
-> Read DescribeIdentityUsageResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeIdentityUsageResponse]
$creadListPrec :: ReadPrec [DescribeIdentityUsageResponse]
readPrec :: ReadPrec DescribeIdentityUsageResponse
$creadPrec :: ReadPrec DescribeIdentityUsageResponse
readList :: ReadS [DescribeIdentityUsageResponse]
$creadList :: ReadS [DescribeIdentityUsageResponse]
readsPrec :: Int -> ReadS DescribeIdentityUsageResponse
$creadsPrec :: Int -> ReadS DescribeIdentityUsageResponse
Prelude.Read, Int -> DescribeIdentityUsageResponse -> ShowS
[DescribeIdentityUsageResponse] -> ShowS
DescribeIdentityUsageResponse -> String
(Int -> DescribeIdentityUsageResponse -> ShowS)
-> (DescribeIdentityUsageResponse -> String)
-> ([DescribeIdentityUsageResponse] -> ShowS)
-> Show DescribeIdentityUsageResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeIdentityUsageResponse] -> ShowS
$cshowList :: [DescribeIdentityUsageResponse] -> ShowS
show :: DescribeIdentityUsageResponse -> String
$cshow :: DescribeIdentityUsageResponse -> String
showsPrec :: Int -> DescribeIdentityUsageResponse -> ShowS
$cshowsPrec :: Int -> DescribeIdentityUsageResponse -> ShowS
Prelude.Show, (forall x.
 DescribeIdentityUsageResponse
 -> Rep DescribeIdentityUsageResponse x)
-> (forall x.
    Rep DescribeIdentityUsageResponse x
    -> DescribeIdentityUsageResponse)
-> Generic DescribeIdentityUsageResponse
forall x.
Rep DescribeIdentityUsageResponse x
-> DescribeIdentityUsageResponse
forall x.
DescribeIdentityUsageResponse
-> Rep DescribeIdentityUsageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeIdentityUsageResponse x
-> DescribeIdentityUsageResponse
$cfrom :: forall x.
DescribeIdentityUsageResponse
-> Rep DescribeIdentityUsageResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeIdentityUsageResponse' 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:
--
-- 'identityUsage', 'describeIdentityUsageResponse_identityUsage' - Usage information for the identity.
--
-- 'httpStatus', 'describeIdentityUsageResponse_httpStatus' - The response's http status code.
newDescribeIdentityUsageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeIdentityUsageResponse
newDescribeIdentityUsageResponse :: Int -> DescribeIdentityUsageResponse
newDescribeIdentityUsageResponse Int
pHttpStatus_ =
  DescribeIdentityUsageResponse' :: Maybe IdentityUsage -> Int -> DescribeIdentityUsageResponse
DescribeIdentityUsageResponse'
    { $sel:identityUsage:DescribeIdentityUsageResponse' :: Maybe IdentityUsage
identityUsage =
        Maybe IdentityUsage
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeIdentityUsageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Usage information for the identity.
describeIdentityUsageResponse_identityUsage :: Lens.Lens' DescribeIdentityUsageResponse (Prelude.Maybe IdentityUsage)
describeIdentityUsageResponse_identityUsage :: (Maybe IdentityUsage -> f (Maybe IdentityUsage))
-> DescribeIdentityUsageResponse -> f DescribeIdentityUsageResponse
describeIdentityUsageResponse_identityUsage = (DescribeIdentityUsageResponse -> Maybe IdentityUsage)
-> (DescribeIdentityUsageResponse
    -> Maybe IdentityUsage -> DescribeIdentityUsageResponse)
-> Lens
     DescribeIdentityUsageResponse
     DescribeIdentityUsageResponse
     (Maybe IdentityUsage)
     (Maybe IdentityUsage)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeIdentityUsageResponse' {Maybe IdentityUsage
identityUsage :: Maybe IdentityUsage
$sel:identityUsage:DescribeIdentityUsageResponse' :: DescribeIdentityUsageResponse -> Maybe IdentityUsage
identityUsage} -> Maybe IdentityUsage
identityUsage) (\s :: DescribeIdentityUsageResponse
s@DescribeIdentityUsageResponse' {} Maybe IdentityUsage
a -> DescribeIdentityUsageResponse
s {$sel:identityUsage:DescribeIdentityUsageResponse' :: Maybe IdentityUsage
identityUsage = Maybe IdentityUsage
a} :: DescribeIdentityUsageResponse)

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

instance Prelude.NFData DescribeIdentityUsageResponse