{-# 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.Detective.ListGraphs
-- 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)
--
-- Returns the list of behavior graphs that the calling account is an
-- administrator account of. This operation can only be called by an
-- administrator account.
--
-- Because an account can currently only be the administrator of one
-- behavior graph within a Region, the results always contain a single
-- behavior graph.
module Amazonka.Detective.ListGraphs
  ( -- * Creating a Request
    ListGraphs (..),
    newListGraphs,

    -- * Request Lenses
    listGraphs_nextToken,
    listGraphs_maxResults,

    -- * Destructuring the Response
    ListGraphsResponse (..),
    newListGraphsResponse,

    -- * Response Lenses
    listGraphsResponse_nextToken,
    listGraphsResponse_graphList,
    listGraphsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Detective.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:/ 'newListGraphs' smart constructor.
data ListGraphs = ListGraphs'
  { -- | For requests to get the next page of results, the pagination token that
    -- was returned with the previous set of results. The initial request does
    -- not include a pagination token.
    ListGraphs -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of graphs to return at a time. The total must be less
    -- than the overall limit on the number of results to return, which is
    -- currently 200.
    ListGraphs -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural
  }
  deriving (ListGraphs -> ListGraphs -> Bool
(ListGraphs -> ListGraphs -> Bool)
-> (ListGraphs -> ListGraphs -> Bool) -> Eq ListGraphs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListGraphs -> ListGraphs -> Bool
$c/= :: ListGraphs -> ListGraphs -> Bool
== :: ListGraphs -> ListGraphs -> Bool
$c== :: ListGraphs -> ListGraphs -> Bool
Prelude.Eq, ReadPrec [ListGraphs]
ReadPrec ListGraphs
Int -> ReadS ListGraphs
ReadS [ListGraphs]
(Int -> ReadS ListGraphs)
-> ReadS [ListGraphs]
-> ReadPrec ListGraphs
-> ReadPrec [ListGraphs]
-> Read ListGraphs
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListGraphs]
$creadListPrec :: ReadPrec [ListGraphs]
readPrec :: ReadPrec ListGraphs
$creadPrec :: ReadPrec ListGraphs
readList :: ReadS [ListGraphs]
$creadList :: ReadS [ListGraphs]
readsPrec :: Int -> ReadS ListGraphs
$creadsPrec :: Int -> ReadS ListGraphs
Prelude.Read, Int -> ListGraphs -> ShowS
[ListGraphs] -> ShowS
ListGraphs -> String
(Int -> ListGraphs -> ShowS)
-> (ListGraphs -> String)
-> ([ListGraphs] -> ShowS)
-> Show ListGraphs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListGraphs] -> ShowS
$cshowList :: [ListGraphs] -> ShowS
show :: ListGraphs -> String
$cshow :: ListGraphs -> String
showsPrec :: Int -> ListGraphs -> ShowS
$cshowsPrec :: Int -> ListGraphs -> ShowS
Prelude.Show, (forall x. ListGraphs -> Rep ListGraphs x)
-> (forall x. Rep ListGraphs x -> ListGraphs) -> Generic ListGraphs
forall x. Rep ListGraphs x -> ListGraphs
forall x. ListGraphs -> Rep ListGraphs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListGraphs x -> ListGraphs
$cfrom :: forall x. ListGraphs -> Rep ListGraphs x
Prelude.Generic)

-- |
-- Create a value of 'ListGraphs' 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', 'listGraphs_nextToken' - For requests to get the next page of results, the pagination token that
-- was returned with the previous set of results. The initial request does
-- not include a pagination token.
--
-- 'maxResults', 'listGraphs_maxResults' - The maximum number of graphs to return at a time. The total must be less
-- than the overall limit on the number of results to return, which is
-- currently 200.
newListGraphs ::
  ListGraphs
newListGraphs :: ListGraphs
newListGraphs =
  ListGraphs' :: Maybe Text -> Maybe Natural -> ListGraphs
ListGraphs'
    { $sel:nextToken:ListGraphs' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListGraphs' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | For requests to get the next page of results, the pagination token that
-- was returned with the previous set of results. The initial request does
-- not include a pagination token.
listGraphs_nextToken :: Lens.Lens' ListGraphs (Prelude.Maybe Prelude.Text)
listGraphs_nextToken :: (Maybe Text -> f (Maybe Text)) -> ListGraphs -> f ListGraphs
listGraphs_nextToken = (ListGraphs -> Maybe Text)
-> (ListGraphs -> Maybe Text -> ListGraphs)
-> Lens ListGraphs ListGraphs (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGraphs' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListGraphs' :: ListGraphs -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListGraphs
s@ListGraphs' {} Maybe Text
a -> ListGraphs
s {$sel:nextToken:ListGraphs' :: Maybe Text
nextToken = Maybe Text
a} :: ListGraphs)

-- | The maximum number of graphs to return at a time. The total must be less
-- than the overall limit on the number of results to return, which is
-- currently 200.
listGraphs_maxResults :: Lens.Lens' ListGraphs (Prelude.Maybe Prelude.Natural)
listGraphs_maxResults :: (Maybe Natural -> f (Maybe Natural)) -> ListGraphs -> f ListGraphs
listGraphs_maxResults = (ListGraphs -> Maybe Natural)
-> (ListGraphs -> Maybe Natural -> ListGraphs)
-> Lens ListGraphs ListGraphs (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGraphs' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListGraphs' :: ListGraphs -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListGraphs
s@ListGraphs' {} Maybe Natural
a -> ListGraphs
s {$sel:maxResults:ListGraphs' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListGraphs)

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

instance Prelude.NFData ListGraphs

instance Core.ToHeaders ListGraphs where
  toHeaders :: ListGraphs -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ListGraphs -> 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 ListGraphs where
  toJSON :: ListGraphs -> Value
toJSON ListGraphs' {Maybe Natural
Maybe Text
maxResults :: Maybe Natural
nextToken :: Maybe Text
$sel:maxResults:ListGraphs' :: ListGraphs -> Maybe Natural
$sel:nextToken:ListGraphs' :: ListGraphs -> 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
"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 ListGraphs where
  toPath :: ListGraphs -> ByteString
toPath = ByteString -> ListGraphs -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/graphs/list"

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

-- | /See:/ 'newListGraphsResponse' smart constructor.
data ListGraphsResponse = ListGraphsResponse'
  { -- | If there are more behavior graphs remaining in the results, then this is
    -- the pagination token to use to request the next page of behavior graphs.
    ListGraphsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of behavior graphs that the account is an administrator account
    -- for.
    ListGraphsResponse -> Maybe [Graph]
graphList :: Prelude.Maybe [Graph],
    -- | The response's http status code.
    ListGraphsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListGraphsResponse -> ListGraphsResponse -> Bool
(ListGraphsResponse -> ListGraphsResponse -> Bool)
-> (ListGraphsResponse -> ListGraphsResponse -> Bool)
-> Eq ListGraphsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListGraphsResponse -> ListGraphsResponse -> Bool
$c/= :: ListGraphsResponse -> ListGraphsResponse -> Bool
== :: ListGraphsResponse -> ListGraphsResponse -> Bool
$c== :: ListGraphsResponse -> ListGraphsResponse -> Bool
Prelude.Eq, ReadPrec [ListGraphsResponse]
ReadPrec ListGraphsResponse
Int -> ReadS ListGraphsResponse
ReadS [ListGraphsResponse]
(Int -> ReadS ListGraphsResponse)
-> ReadS [ListGraphsResponse]
-> ReadPrec ListGraphsResponse
-> ReadPrec [ListGraphsResponse]
-> Read ListGraphsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListGraphsResponse]
$creadListPrec :: ReadPrec [ListGraphsResponse]
readPrec :: ReadPrec ListGraphsResponse
$creadPrec :: ReadPrec ListGraphsResponse
readList :: ReadS [ListGraphsResponse]
$creadList :: ReadS [ListGraphsResponse]
readsPrec :: Int -> ReadS ListGraphsResponse
$creadsPrec :: Int -> ReadS ListGraphsResponse
Prelude.Read, Int -> ListGraphsResponse -> ShowS
[ListGraphsResponse] -> ShowS
ListGraphsResponse -> String
(Int -> ListGraphsResponse -> ShowS)
-> (ListGraphsResponse -> String)
-> ([ListGraphsResponse] -> ShowS)
-> Show ListGraphsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListGraphsResponse] -> ShowS
$cshowList :: [ListGraphsResponse] -> ShowS
show :: ListGraphsResponse -> String
$cshow :: ListGraphsResponse -> String
showsPrec :: Int -> ListGraphsResponse -> ShowS
$cshowsPrec :: Int -> ListGraphsResponse -> ShowS
Prelude.Show, (forall x. ListGraphsResponse -> Rep ListGraphsResponse x)
-> (forall x. Rep ListGraphsResponse x -> ListGraphsResponse)
-> Generic ListGraphsResponse
forall x. Rep ListGraphsResponse x -> ListGraphsResponse
forall x. ListGraphsResponse -> Rep ListGraphsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListGraphsResponse x -> ListGraphsResponse
$cfrom :: forall x. ListGraphsResponse -> Rep ListGraphsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListGraphsResponse' 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', 'listGraphsResponse_nextToken' - If there are more behavior graphs remaining in the results, then this is
-- the pagination token to use to request the next page of behavior graphs.
--
-- 'graphList', 'listGraphsResponse_graphList' - A list of behavior graphs that the account is an administrator account
-- for.
--
-- 'httpStatus', 'listGraphsResponse_httpStatus' - The response's http status code.
newListGraphsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListGraphsResponse
newListGraphsResponse :: Int -> ListGraphsResponse
newListGraphsResponse Int
pHttpStatus_ =
  ListGraphsResponse' :: Maybe Text -> Maybe [Graph] -> Int -> ListGraphsResponse
ListGraphsResponse'
    { $sel:nextToken:ListGraphsResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:graphList:ListGraphsResponse' :: Maybe [Graph]
graphList = Maybe [Graph]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListGraphsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If there are more behavior graphs remaining in the results, then this is
-- the pagination token to use to request the next page of behavior graphs.
listGraphsResponse_nextToken :: Lens.Lens' ListGraphsResponse (Prelude.Maybe Prelude.Text)
listGraphsResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListGraphsResponse -> f ListGraphsResponse
listGraphsResponse_nextToken = (ListGraphsResponse -> Maybe Text)
-> (ListGraphsResponse -> Maybe Text -> ListGraphsResponse)
-> Lens
     ListGraphsResponse ListGraphsResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGraphsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListGraphsResponse' :: ListGraphsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListGraphsResponse
s@ListGraphsResponse' {} Maybe Text
a -> ListGraphsResponse
s {$sel:nextToken:ListGraphsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListGraphsResponse)

-- | A list of behavior graphs that the account is an administrator account
-- for.
listGraphsResponse_graphList :: Lens.Lens' ListGraphsResponse (Prelude.Maybe [Graph])
listGraphsResponse_graphList :: (Maybe [Graph] -> f (Maybe [Graph]))
-> ListGraphsResponse -> f ListGraphsResponse
listGraphsResponse_graphList = (ListGraphsResponse -> Maybe [Graph])
-> (ListGraphsResponse -> Maybe [Graph] -> ListGraphsResponse)
-> Lens
     ListGraphsResponse
     ListGraphsResponse
     (Maybe [Graph])
     (Maybe [Graph])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGraphsResponse' {Maybe [Graph]
graphList :: Maybe [Graph]
$sel:graphList:ListGraphsResponse' :: ListGraphsResponse -> Maybe [Graph]
graphList} -> Maybe [Graph]
graphList) (\s :: ListGraphsResponse
s@ListGraphsResponse' {} Maybe [Graph]
a -> ListGraphsResponse
s {$sel:graphList:ListGraphsResponse' :: Maybe [Graph]
graphList = Maybe [Graph]
a} :: ListGraphsResponse) ((Maybe [Graph] -> f (Maybe [Graph]))
 -> ListGraphsResponse -> f ListGraphsResponse)
-> ((Maybe [Graph] -> f (Maybe [Graph]))
    -> Maybe [Graph] -> f (Maybe [Graph]))
-> (Maybe [Graph] -> f (Maybe [Graph]))
-> ListGraphsResponse
-> f ListGraphsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Graph] [Graph] [Graph] [Graph]
-> Iso
     (Maybe [Graph]) (Maybe [Graph]) (Maybe [Graph]) (Maybe [Graph])
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 [Graph] [Graph] [Graph] [Graph]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ListGraphsResponse