{-# 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.Organizations.ListRoots
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the roots that are defined in the current organization.
--
-- Always check the @NextToken@ response parameter for a @null@ value when
-- calling a @List*@ operation. These operations can occasionally return an
-- empty set of results even when there are more results available. The
-- @NextToken@ response parameter value is @null@ /only/ when there are no
-- more results to display.
--
-- This operation can be called only from the organization\'s management
-- account or by a member account that is a delegated administrator for an
-- Amazon Web Services service.
--
-- Policy types can be enabled and disabled in roots. This is distinct from
-- whether they\'re available in the organization. When you enable all
-- features, you make policy types available for use in that organization.
-- Individual policy types can then be enabled and disabled in a root. To
-- see the availability of a policy type in an organization, use
-- DescribeOrganization.
--
-- This operation returns paginated results.
module Amazonka.Organizations.ListRoots
  ( -- * Creating a Request
    ListRoots (..),
    newListRoots,

    -- * Request Lenses
    listRoots_maxResults,
    listRoots_nextToken,

    -- * Destructuring the Response
    ListRootsResponse (..),
    newListRootsResponse,

    -- * Response Lenses
    listRootsResponse_nextToken,
    listRootsResponse_roots,
    listRootsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Organizations.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListRoots' smart constructor.
data ListRoots = ListRoots'
  { -- | The total number of results that you want included on each page of the
    -- response. If you do not include this parameter, it defaults to a value
    -- that is specific to the operation. If additional items exist beyond the
    -- maximum you specify, the @NextToken@ response element is present and has
    -- a value (is not null). Include that value as the @NextToken@ request
    -- parameter in the next call to the operation to get the next part of the
    -- results. Note that Organizations might return fewer results than the
    -- maximum even when there are more results available. You should check
    -- @NextToken@ after every operation to ensure that you receive all of the
    -- results.
    ListRoots -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The parameter for receiving additional results if you receive a
    -- @NextToken@ response in a previous request. A @NextToken@ response
    -- indicates that more output is available. Set this parameter to the value
    -- of the previous call\'s @NextToken@ response to indicate where the
    -- output should continue from.
    ListRoots -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListRoots -> ListRoots -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRoots -> ListRoots -> Bool
$c/= :: ListRoots -> ListRoots -> Bool
== :: ListRoots -> ListRoots -> Bool
$c== :: ListRoots -> ListRoots -> Bool
Prelude.Eq, ReadPrec [ListRoots]
ReadPrec ListRoots
Int -> ReadS ListRoots
ReadS [ListRoots]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRoots]
$creadListPrec :: ReadPrec [ListRoots]
readPrec :: ReadPrec ListRoots
$creadPrec :: ReadPrec ListRoots
readList :: ReadS [ListRoots]
$creadList :: ReadS [ListRoots]
readsPrec :: Int -> ReadS ListRoots
$creadsPrec :: Int -> ReadS ListRoots
Prelude.Read, Int -> ListRoots -> ShowS
[ListRoots] -> ShowS
ListRoots -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRoots] -> ShowS
$cshowList :: [ListRoots] -> ShowS
show :: ListRoots -> String
$cshow :: ListRoots -> String
showsPrec :: Int -> ListRoots -> ShowS
$cshowsPrec :: Int -> ListRoots -> ShowS
Prelude.Show, forall x. Rep ListRoots x -> ListRoots
forall x. ListRoots -> Rep ListRoots x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRoots x -> ListRoots
$cfrom :: forall x. ListRoots -> Rep ListRoots x
Prelude.Generic)

-- |
-- Create a value of 'ListRoots' 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', 'listRoots_maxResults' - The total number of results that you want included on each page of the
-- response. If you do not include this parameter, it defaults to a value
-- that is specific to the operation. If additional items exist beyond the
-- maximum you specify, the @NextToken@ response element is present and has
-- a value (is not null). Include that value as the @NextToken@ request
-- parameter in the next call to the operation to get the next part of the
-- results. Note that Organizations might return fewer results than the
-- maximum even when there are more results available. You should check
-- @NextToken@ after every operation to ensure that you receive all of the
-- results.
--
-- 'nextToken', 'listRoots_nextToken' - The parameter for receiving additional results if you receive a
-- @NextToken@ response in a previous request. A @NextToken@ response
-- indicates that more output is available. Set this parameter to the value
-- of the previous call\'s @NextToken@ response to indicate where the
-- output should continue from.
newListRoots ::
  ListRoots
newListRoots :: ListRoots
newListRoots =
  ListRoots'
    { $sel:maxResults:ListRoots' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListRoots' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The total number of results that you want included on each page of the
-- response. If you do not include this parameter, it defaults to a value
-- that is specific to the operation. If additional items exist beyond the
-- maximum you specify, the @NextToken@ response element is present and has
-- a value (is not null). Include that value as the @NextToken@ request
-- parameter in the next call to the operation to get the next part of the
-- results. Note that Organizations might return fewer results than the
-- maximum even when there are more results available. You should check
-- @NextToken@ after every operation to ensure that you receive all of the
-- results.
listRoots_maxResults :: Lens.Lens' ListRoots (Prelude.Maybe Prelude.Natural)
listRoots_maxResults :: Lens' ListRoots (Maybe Natural)
listRoots_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRoots' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListRoots' :: ListRoots -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListRoots
s@ListRoots' {} Maybe Natural
a -> ListRoots
s {$sel:maxResults:ListRoots' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListRoots)

-- | The parameter for receiving additional results if you receive a
-- @NextToken@ response in a previous request. A @NextToken@ response
-- indicates that more output is available. Set this parameter to the value
-- of the previous call\'s @NextToken@ response to indicate where the
-- output should continue from.
listRoots_nextToken :: Lens.Lens' ListRoots (Prelude.Maybe Prelude.Text)
listRoots_nextToken :: Lens' ListRoots (Maybe Text)
listRoots_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRoots' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListRoots' :: ListRoots -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListRoots
s@ListRoots' {} Maybe Text
a -> ListRoots
s {$sel:nextToken:ListRoots' :: Maybe Text
nextToken = Maybe Text
a} :: ListRoots)

instance Core.AWSPager ListRoots where
  page :: ListRoots -> AWSResponse ListRoots -> Maybe ListRoots
page ListRoots
rq AWSResponse ListRoots
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListRoots
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRootsResponse (Maybe Text)
listRootsResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListRoots
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRootsResponse (Maybe [Root])
listRootsResponse_roots
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListRoots
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListRoots (Maybe Text)
listRoots_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListRoots
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRootsResponse (Maybe Text)
listRootsResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListRoots where
  type AWSResponse ListRoots = ListRootsResponse
  request :: (Service -> Service) -> ListRoots -> Request ListRoots
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 ListRoots
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListRoots)))
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 Text -> Maybe [Root] -> Int -> ListRootsResponse
ListRootsResponse'
            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
"NextToken")
            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
"Roots" 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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListRoots where
  hashWithSalt :: Int -> ListRoots -> Int
hashWithSalt Int
_salt ListRoots' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListRoots' :: ListRoots -> Maybe Text
$sel:maxResults:ListRoots' :: ListRoots -> 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 ListRoots where
  rnf :: ListRoots -> ()
rnf ListRoots' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListRoots' :: ListRoots -> Maybe Text
$sel:maxResults:ListRoots' :: ListRoots -> 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 ListRoots where
  toHeaders :: ListRoots -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AWSOrganizationsV20161128.ListRoots" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListRoots where
  toJSON :: ListRoots -> Value
toJSON ListRoots' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListRoots' :: ListRoots -> Maybe Text
$sel:maxResults:ListRoots' :: ListRoots -> 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 ListRoots where
  toPath :: ListRoots -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListRootsResponse' smart constructor.
data ListRootsResponse = ListRootsResponse'
  { -- | If present, indicates that more output is available than is included in
    -- the current response. Use this value in the @NextToken@ request
    -- parameter in a subsequent call to the operation to get the next part of
    -- the output. You should repeat this until the @NextToken@ response
    -- element comes back as @null@.
    ListRootsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of roots that are defined in an organization.
    ListRootsResponse -> Maybe [Root]
roots :: Prelude.Maybe [Root],
    -- | The response's http status code.
    ListRootsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListRootsResponse -> ListRootsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRootsResponse -> ListRootsResponse -> Bool
$c/= :: ListRootsResponse -> ListRootsResponse -> Bool
== :: ListRootsResponse -> ListRootsResponse -> Bool
$c== :: ListRootsResponse -> ListRootsResponse -> Bool
Prelude.Eq, ReadPrec [ListRootsResponse]
ReadPrec ListRootsResponse
Int -> ReadS ListRootsResponse
ReadS [ListRootsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRootsResponse]
$creadListPrec :: ReadPrec [ListRootsResponse]
readPrec :: ReadPrec ListRootsResponse
$creadPrec :: ReadPrec ListRootsResponse
readList :: ReadS [ListRootsResponse]
$creadList :: ReadS [ListRootsResponse]
readsPrec :: Int -> ReadS ListRootsResponse
$creadsPrec :: Int -> ReadS ListRootsResponse
Prelude.Read, Int -> ListRootsResponse -> ShowS
[ListRootsResponse] -> ShowS
ListRootsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRootsResponse] -> ShowS
$cshowList :: [ListRootsResponse] -> ShowS
show :: ListRootsResponse -> String
$cshow :: ListRootsResponse -> String
showsPrec :: Int -> ListRootsResponse -> ShowS
$cshowsPrec :: Int -> ListRootsResponse -> ShowS
Prelude.Show, forall x. Rep ListRootsResponse x -> ListRootsResponse
forall x. ListRootsResponse -> Rep ListRootsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRootsResponse x -> ListRootsResponse
$cfrom :: forall x. ListRootsResponse -> Rep ListRootsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListRootsResponse' 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', 'listRootsResponse_nextToken' - If present, indicates that more output is available than is included in
-- the current response. Use this value in the @NextToken@ request
-- parameter in a subsequent call to the operation to get the next part of
-- the output. You should repeat this until the @NextToken@ response
-- element comes back as @null@.
--
-- 'roots', 'listRootsResponse_roots' - A list of roots that are defined in an organization.
--
-- 'httpStatus', 'listRootsResponse_httpStatus' - The response's http status code.
newListRootsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListRootsResponse
newListRootsResponse :: Int -> ListRootsResponse
newListRootsResponse Int
pHttpStatus_ =
  ListRootsResponse'
    { $sel:nextToken:ListRootsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:roots:ListRootsResponse' :: Maybe [Root]
roots = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListRootsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If present, indicates that more output is available than is included in
-- the current response. Use this value in the @NextToken@ request
-- parameter in a subsequent call to the operation to get the next part of
-- the output. You should repeat this until the @NextToken@ response
-- element comes back as @null@.
listRootsResponse_nextToken :: Lens.Lens' ListRootsResponse (Prelude.Maybe Prelude.Text)
listRootsResponse_nextToken :: Lens' ListRootsResponse (Maybe Text)
listRootsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRootsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListRootsResponse' :: ListRootsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListRootsResponse
s@ListRootsResponse' {} Maybe Text
a -> ListRootsResponse
s {$sel:nextToken:ListRootsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListRootsResponse)

-- | A list of roots that are defined in an organization.
listRootsResponse_roots :: Lens.Lens' ListRootsResponse (Prelude.Maybe [Root])
listRootsResponse_roots :: Lens' ListRootsResponse (Maybe [Root])
listRootsResponse_roots = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRootsResponse' {Maybe [Root]
roots :: Maybe [Root]
$sel:roots:ListRootsResponse' :: ListRootsResponse -> Maybe [Root]
roots} -> Maybe [Root]
roots) (\s :: ListRootsResponse
s@ListRootsResponse' {} Maybe [Root]
a -> ListRootsResponse
s {$sel:roots:ListRootsResponse' :: Maybe [Root]
roots = Maybe [Root]
a} :: ListRootsResponse) 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

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

instance Prelude.NFData ListRootsResponse where
  rnf :: ListRootsResponse -> ()
rnf ListRootsResponse' {Int
Maybe [Root]
Maybe Text
httpStatus :: Int
roots :: Maybe [Root]
nextToken :: Maybe Text
$sel:httpStatus:ListRootsResponse' :: ListRootsResponse -> Int
$sel:roots:ListRootsResponse' :: ListRootsResponse -> Maybe [Root]
$sel:nextToken:ListRootsResponse' :: ListRootsResponse -> Maybe Text
..} =
    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 Maybe [Root]
roots
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus