{-# 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.FraudDetector.GetLabels
-- 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 all labels or a specific label if name is provided. This is a
-- paginated API. If you provide a null @maxResults@, this action retrieves
-- a maximum of 50 records per page. If you provide a @maxResults@, the
-- value must be between 10 and 50. To get the next page results, provide
-- the pagination token from the @GetGetLabelsResponse@ as part of your
-- request. A null pagination token fetches the records from the beginning.
module Amazonka.FraudDetector.GetLabels
  ( -- * Creating a Request
    GetLabels (..),
    newGetLabels,

    -- * Request Lenses
    getLabels_nextToken,
    getLabels_name,
    getLabels_maxResults,

    -- * Destructuring the Response
    GetLabelsResponse (..),
    newGetLabelsResponse,

    -- * Response Lenses
    getLabelsResponse_nextToken,
    getLabelsResponse_labels,
    getLabelsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.FraudDetector.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:/ 'newGetLabels' smart constructor.
data GetLabels = GetLabels'
  { -- | The next token for the subsequent request.
    GetLabels -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the label or labels to get.
    GetLabels -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of objects to return for the request.
    GetLabels -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural
  }
  deriving (GetLabels -> GetLabels -> Bool
(GetLabels -> GetLabels -> Bool)
-> (GetLabels -> GetLabels -> Bool) -> Eq GetLabels
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetLabels -> GetLabels -> Bool
$c/= :: GetLabels -> GetLabels -> Bool
== :: GetLabels -> GetLabels -> Bool
$c== :: GetLabels -> GetLabels -> Bool
Prelude.Eq, ReadPrec [GetLabels]
ReadPrec GetLabels
Int -> ReadS GetLabels
ReadS [GetLabels]
(Int -> ReadS GetLabels)
-> ReadS [GetLabels]
-> ReadPrec GetLabels
-> ReadPrec [GetLabels]
-> Read GetLabels
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetLabels]
$creadListPrec :: ReadPrec [GetLabels]
readPrec :: ReadPrec GetLabels
$creadPrec :: ReadPrec GetLabels
readList :: ReadS [GetLabels]
$creadList :: ReadS [GetLabels]
readsPrec :: Int -> ReadS GetLabels
$creadsPrec :: Int -> ReadS GetLabels
Prelude.Read, Int -> GetLabels -> ShowS
[GetLabels] -> ShowS
GetLabels -> String
(Int -> GetLabels -> ShowS)
-> (GetLabels -> String)
-> ([GetLabels] -> ShowS)
-> Show GetLabels
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetLabels] -> ShowS
$cshowList :: [GetLabels] -> ShowS
show :: GetLabels -> String
$cshow :: GetLabels -> String
showsPrec :: Int -> GetLabels -> ShowS
$cshowsPrec :: Int -> GetLabels -> ShowS
Prelude.Show, (forall x. GetLabels -> Rep GetLabels x)
-> (forall x. Rep GetLabels x -> GetLabels) -> Generic GetLabels
forall x. Rep GetLabels x -> GetLabels
forall x. GetLabels -> Rep GetLabels x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetLabels x -> GetLabels
$cfrom :: forall x. GetLabels -> Rep GetLabels x
Prelude.Generic)

-- |
-- Create a value of 'GetLabels' 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:
--
-- 'nextToken', 'getLabels_nextToken' - The next token for the subsequent request.
--
-- 'name', 'getLabels_name' - The name of the label or labels to get.
--
-- 'maxResults', 'getLabels_maxResults' - The maximum number of objects to return for the request.
newGetLabels ::
  GetLabels
newGetLabels :: GetLabels
newGetLabels =
  GetLabels' :: Maybe Text -> Maybe Text -> Maybe Natural -> GetLabels
GetLabels'
    { $sel:nextToken:GetLabels' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:GetLabels' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:GetLabels' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The next token for the subsequent request.
getLabels_nextToken :: Lens.Lens' GetLabels (Prelude.Maybe Prelude.Text)
getLabels_nextToken :: (Maybe Text -> f (Maybe Text)) -> GetLabels -> f GetLabels
getLabels_nextToken = (GetLabels -> Maybe Text)
-> (GetLabels -> Maybe Text -> GetLabels)
-> Lens GetLabels GetLabels (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLabels' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetLabels' :: GetLabels -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetLabels
s@GetLabels' {} Maybe Text
a -> GetLabels
s {$sel:nextToken:GetLabels' :: Maybe Text
nextToken = Maybe Text
a} :: GetLabels)

-- | The name of the label or labels to get.
getLabels_name :: Lens.Lens' GetLabels (Prelude.Maybe Prelude.Text)
getLabels_name :: (Maybe Text -> f (Maybe Text)) -> GetLabels -> f GetLabels
getLabels_name = (GetLabels -> Maybe Text)
-> (GetLabels -> Maybe Text -> GetLabels)
-> Lens GetLabels GetLabels (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLabels' {Maybe Text
name :: Maybe Text
$sel:name:GetLabels' :: GetLabels -> Maybe Text
name} -> Maybe Text
name) (\s :: GetLabels
s@GetLabels' {} Maybe Text
a -> GetLabels
s {$sel:name:GetLabels' :: Maybe Text
name = Maybe Text
a} :: GetLabels)

-- | The maximum number of objects to return for the request.
getLabels_maxResults :: Lens.Lens' GetLabels (Prelude.Maybe Prelude.Natural)
getLabels_maxResults :: (Maybe Natural -> f (Maybe Natural)) -> GetLabels -> f GetLabels
getLabels_maxResults = (GetLabels -> Maybe Natural)
-> (GetLabels -> Maybe Natural -> GetLabels)
-> Lens GetLabels GetLabels (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLabels' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:GetLabels' :: GetLabels -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: GetLabels
s@GetLabels' {} Maybe Natural
a -> GetLabels
s {$sel:maxResults:GetLabels' :: Maybe Natural
maxResults = Maybe Natural
a} :: GetLabels)

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

instance Prelude.NFData GetLabels

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

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

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

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

-- |
-- Create a value of 'GetLabelsResponse' 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:
--
-- 'nextToken', 'getLabelsResponse_nextToken' - The next page token.
--
-- 'labels', 'getLabelsResponse_labels' - An array of labels.
--
-- 'httpStatus', 'getLabelsResponse_httpStatus' - The response's http status code.
newGetLabelsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetLabelsResponse
newGetLabelsResponse :: Int -> GetLabelsResponse
newGetLabelsResponse Int
pHttpStatus_ =
  GetLabelsResponse' :: Maybe Text -> Maybe [Label] -> Int -> GetLabelsResponse
GetLabelsResponse'
    { $sel:nextToken:GetLabelsResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:labels:GetLabelsResponse' :: Maybe [Label]
labels = Maybe [Label]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetLabelsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The next page token.
getLabelsResponse_nextToken :: Lens.Lens' GetLabelsResponse (Prelude.Maybe Prelude.Text)
getLabelsResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> GetLabelsResponse -> f GetLabelsResponse
getLabelsResponse_nextToken = (GetLabelsResponse -> Maybe Text)
-> (GetLabelsResponse -> Maybe Text -> GetLabelsResponse)
-> Lens
     GetLabelsResponse GetLabelsResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLabelsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetLabelsResponse' :: GetLabelsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetLabelsResponse
s@GetLabelsResponse' {} Maybe Text
a -> GetLabelsResponse
s {$sel:nextToken:GetLabelsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: GetLabelsResponse)

-- | An array of labels.
getLabelsResponse_labels :: Lens.Lens' GetLabelsResponse (Prelude.Maybe [Label])
getLabelsResponse_labels :: (Maybe [Label] -> f (Maybe [Label]))
-> GetLabelsResponse -> f GetLabelsResponse
getLabelsResponse_labels = (GetLabelsResponse -> Maybe [Label])
-> (GetLabelsResponse -> Maybe [Label] -> GetLabelsResponse)
-> Lens
     GetLabelsResponse GetLabelsResponse (Maybe [Label]) (Maybe [Label])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLabelsResponse' {Maybe [Label]
labels :: Maybe [Label]
$sel:labels:GetLabelsResponse' :: GetLabelsResponse -> Maybe [Label]
labels} -> Maybe [Label]
labels) (\s :: GetLabelsResponse
s@GetLabelsResponse' {} Maybe [Label]
a -> GetLabelsResponse
s {$sel:labels:GetLabelsResponse' :: Maybe [Label]
labels = Maybe [Label]
a} :: GetLabelsResponse) ((Maybe [Label] -> f (Maybe [Label]))
 -> GetLabelsResponse -> f GetLabelsResponse)
-> ((Maybe [Label] -> f (Maybe [Label]))
    -> Maybe [Label] -> f (Maybe [Label]))
-> (Maybe [Label] -> f (Maybe [Label]))
-> GetLabelsResponse
-> f GetLabelsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Label] [Label] [Label] [Label]
-> Iso
     (Maybe [Label]) (Maybe [Label]) (Maybe [Label]) (Maybe [Label])
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 [Label] [Label] [Label] [Label]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetLabelsResponse