{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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_maxResults,
    listGraphs_nextToken,

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

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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Detective.Types
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'
  { -- | 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,
    -- | 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
  }
  deriving (ListGraphs -> ListGraphs -> Bool
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]
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
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. 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:
--
-- '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.
--
-- '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.
newListGraphs ::
  ListGraphs
newListGraphs :: ListGraphs
newListGraphs =
  ListGraphs'
    { $sel:maxResults:ListGraphs' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListGraphs' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' ListGraphs (Maybe Natural)
listGraphs_maxResults = 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)

-- | 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 :: Lens' ListGraphs (Maybe Text)
listGraphs_nextToken = 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)

instance Core.AWSRequest ListGraphs where
  type AWSResponse ListGraphs = ListGraphsResponse
  request :: (Service -> Service) -> ListGraphs -> Request ListGraphs
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListGraphs
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListGraphs)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Graph] -> Maybe Text -> Int -> ListGraphsResponse
ListGraphsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"GraphList" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListGraphs where
  hashWithSalt :: Int -> ListGraphs -> Int
hashWithSalt Int
_salt ListGraphs' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListGraphs' :: ListGraphs -> Maybe Text
$sel:maxResults:ListGraphs' :: ListGraphs -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData ListGraphs where
  rnf :: ListGraphs -> ()
rnf ListGraphs' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListGraphs' :: ListGraphs -> Maybe Text
$sel:maxResults:ListGraphs' :: ListGraphs -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

instance Data.ToHeaders ListGraphs where
  toHeaders :: ListGraphs -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListGraphs where
  toJSON :: ListGraphs -> Value
toJSON ListGraphs' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListGraphs' :: ListGraphs -> Maybe Text
$sel:maxResults:ListGraphs' :: ListGraphs -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxResults" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            (Key
"NextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken
          ]
      )

instance Data.ToPath ListGraphs where
  toPath :: ListGraphs -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/graphs/list"

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

-- | /See:/ 'newListGraphsResponse' smart constructor.
data ListGraphsResponse = ListGraphsResponse'
  { -- | A list of behavior graphs that the account is an administrator account
    -- for.
    ListGraphsResponse -> Maybe [Graph]
graphList :: Prelude.Maybe [Graph],
    -- | 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,
    -- | The response's http status code.
    ListGraphsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListGraphsResponse -> ListGraphsResponse -> Bool
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]
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
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. 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:
--
-- 'graphList', 'listGraphsResponse_graphList' - A list of behavior graphs that the account is an administrator account
-- for.
--
-- '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.
--
-- 'httpStatus', 'listGraphsResponse_httpStatus' - The response's http status code.
newListGraphsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListGraphsResponse
newListGraphsResponse :: Int -> ListGraphsResponse
newListGraphsResponse Int
pHttpStatus_ =
  ListGraphsResponse'
    { $sel:graphList:ListGraphsResponse' :: Maybe [Graph]
graphList = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListGraphsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListGraphsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | 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 :: Lens' ListGraphsResponse (Maybe Text)
listGraphsResponse_nextToken = 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)

-- | The response's http status code.
listGraphsResponse_httpStatus :: Lens.Lens' ListGraphsResponse Prelude.Int
listGraphsResponse_httpStatus :: Lens' ListGraphsResponse Int
listGraphsResponse_httpStatus = 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 where
  rnf :: ListGraphsResponse -> ()
rnf ListGraphsResponse' {Int
Maybe [Graph]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
graphList :: Maybe [Graph]
$sel:httpStatus:ListGraphsResponse' :: ListGraphsResponse -> Int
$sel:nextToken:ListGraphsResponse' :: ListGraphsResponse -> Maybe Text
$sel:graphList:ListGraphsResponse' :: ListGraphsResponse -> Maybe [Graph]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Graph]
graphList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus