{-# 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.WorkMail.ListOrganizations
-- 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 summaries of the customer\'s organizations.
--
-- This operation returns paginated results.
module Amazonka.WorkMail.ListOrganizations
  ( -- * Creating a Request
    ListOrganizations (..),
    newListOrganizations,

    -- * Request Lenses
    listOrganizations_maxResults,
    listOrganizations_nextToken,

    -- * Destructuring the Response
    ListOrganizationsResponse (..),
    newListOrganizationsResponse,

    -- * Response Lenses
    listOrganizationsResponse_nextToken,
    listOrganizationsResponse_organizationSummaries,
    listOrganizationsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListOrganizations' smart constructor.
data ListOrganizations = ListOrganizations'
  { -- | The maximum number of results to return in a single call.
    ListOrganizations -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token to use to retrieve the next page of results. The first call
    -- does not contain any tokens.
    ListOrganizations -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListOrganizations -> ListOrganizations -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListOrganizations -> ListOrganizations -> Bool
$c/= :: ListOrganizations -> ListOrganizations -> Bool
== :: ListOrganizations -> ListOrganizations -> Bool
$c== :: ListOrganizations -> ListOrganizations -> Bool
Prelude.Eq, ReadPrec [ListOrganizations]
ReadPrec ListOrganizations
Int -> ReadS ListOrganizations
ReadS [ListOrganizations]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListOrganizations]
$creadListPrec :: ReadPrec [ListOrganizations]
readPrec :: ReadPrec ListOrganizations
$creadPrec :: ReadPrec ListOrganizations
readList :: ReadS [ListOrganizations]
$creadList :: ReadS [ListOrganizations]
readsPrec :: Int -> ReadS ListOrganizations
$creadsPrec :: Int -> ReadS ListOrganizations
Prelude.Read, Int -> ListOrganizations -> ShowS
[ListOrganizations] -> ShowS
ListOrganizations -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListOrganizations] -> ShowS
$cshowList :: [ListOrganizations] -> ShowS
show :: ListOrganizations -> String
$cshow :: ListOrganizations -> String
showsPrec :: Int -> ListOrganizations -> ShowS
$cshowsPrec :: Int -> ListOrganizations -> ShowS
Prelude.Show, forall x. Rep ListOrganizations x -> ListOrganizations
forall x. ListOrganizations -> Rep ListOrganizations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListOrganizations x -> ListOrganizations
$cfrom :: forall x. ListOrganizations -> Rep ListOrganizations x
Prelude.Generic)

-- |
-- Create a value of 'ListOrganizations' 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', 'listOrganizations_maxResults' - The maximum number of results to return in a single call.
--
-- 'nextToken', 'listOrganizations_nextToken' - The token to use to retrieve the next page of results. The first call
-- does not contain any tokens.
newListOrganizations ::
  ListOrganizations
newListOrganizations :: ListOrganizations
newListOrganizations =
  ListOrganizations'
    { $sel:maxResults:ListOrganizations' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListOrganizations' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of results to return in a single call.
listOrganizations_maxResults :: Lens.Lens' ListOrganizations (Prelude.Maybe Prelude.Natural)
listOrganizations_maxResults :: Lens' ListOrganizations (Maybe Natural)
listOrganizations_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOrganizations' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListOrganizations' :: ListOrganizations -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListOrganizations
s@ListOrganizations' {} Maybe Natural
a -> ListOrganizations
s {$sel:maxResults:ListOrganizations' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListOrganizations)

-- | The token to use to retrieve the next page of results. The first call
-- does not contain any tokens.
listOrganizations_nextToken :: Lens.Lens' ListOrganizations (Prelude.Maybe Prelude.Text)
listOrganizations_nextToken :: Lens' ListOrganizations (Maybe Text)
listOrganizations_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOrganizations' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListOrganizations' :: ListOrganizations -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListOrganizations
s@ListOrganizations' {} Maybe Text
a -> ListOrganizations
s {$sel:nextToken:ListOrganizations' :: Maybe Text
nextToken = Maybe Text
a} :: ListOrganizations)

instance Core.AWSPager ListOrganizations where
  page :: ListOrganizations
-> AWSResponse ListOrganizations -> Maybe ListOrganizations
page ListOrganizations
rq AWSResponse ListOrganizations
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListOrganizations
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListOrganizationsResponse (Maybe Text)
listOrganizationsResponse_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 ListOrganizations
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListOrganizationsResponse (Maybe [OrganizationSummary])
listOrganizationsResponse_organizationSummaries
            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.$ ListOrganizations
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListOrganizations (Maybe Text)
listOrganizations_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListOrganizations
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListOrganizationsResponse (Maybe Text)
listOrganizationsResponse_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 ListOrganizations where
  type
    AWSResponse ListOrganizations =
      ListOrganizationsResponse
  request :: (Service -> Service)
-> ListOrganizations -> Request ListOrganizations
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 ListOrganizations
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListOrganizations)))
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 [OrganizationSummary] -> Int -> ListOrganizationsResponse
ListOrganizationsResponse'
            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
"OrganizationSummaries"
                            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 ListOrganizations where
  hashWithSalt :: Int -> ListOrganizations -> Int
hashWithSalt Int
_salt ListOrganizations' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListOrganizations' :: ListOrganizations -> Maybe Text
$sel:maxResults:ListOrganizations' :: ListOrganizations -> 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 ListOrganizations where
  rnf :: ListOrganizations -> ()
rnf ListOrganizations' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListOrganizations' :: ListOrganizations -> Maybe Text
$sel:maxResults:ListOrganizations' :: ListOrganizations -> 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 ListOrganizations where
  toHeaders :: ListOrganizations -> 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
"WorkMailService.ListOrganizations" ::
                          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 ListOrganizations where
  toJSON :: ListOrganizations -> Value
toJSON ListOrganizations' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListOrganizations' :: ListOrganizations -> Maybe Text
$sel:maxResults:ListOrganizations' :: ListOrganizations -> 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 ListOrganizations where
  toPath :: ListOrganizations -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListOrganizationsResponse' smart constructor.
data ListOrganizationsResponse = ListOrganizationsResponse'
  { -- | The token to use to retrieve the next page of results. The value is
    -- \"null\" when there are no more results to return.
    ListOrganizationsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The overview of owned organizations presented as a list of organization
    -- summaries.
    ListOrganizationsResponse -> Maybe [OrganizationSummary]
organizationSummaries :: Prelude.Maybe [OrganizationSummary],
    -- | The response's http status code.
    ListOrganizationsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListOrganizationsResponse -> ListOrganizationsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListOrganizationsResponse -> ListOrganizationsResponse -> Bool
$c/= :: ListOrganizationsResponse -> ListOrganizationsResponse -> Bool
== :: ListOrganizationsResponse -> ListOrganizationsResponse -> Bool
$c== :: ListOrganizationsResponse -> ListOrganizationsResponse -> Bool
Prelude.Eq, ReadPrec [ListOrganizationsResponse]
ReadPrec ListOrganizationsResponse
Int -> ReadS ListOrganizationsResponse
ReadS [ListOrganizationsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListOrganizationsResponse]
$creadListPrec :: ReadPrec [ListOrganizationsResponse]
readPrec :: ReadPrec ListOrganizationsResponse
$creadPrec :: ReadPrec ListOrganizationsResponse
readList :: ReadS [ListOrganizationsResponse]
$creadList :: ReadS [ListOrganizationsResponse]
readsPrec :: Int -> ReadS ListOrganizationsResponse
$creadsPrec :: Int -> ReadS ListOrganizationsResponse
Prelude.Read, Int -> ListOrganizationsResponse -> ShowS
[ListOrganizationsResponse] -> ShowS
ListOrganizationsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListOrganizationsResponse] -> ShowS
$cshowList :: [ListOrganizationsResponse] -> ShowS
show :: ListOrganizationsResponse -> String
$cshow :: ListOrganizationsResponse -> String
showsPrec :: Int -> ListOrganizationsResponse -> ShowS
$cshowsPrec :: Int -> ListOrganizationsResponse -> ShowS
Prelude.Show, forall x.
Rep ListOrganizationsResponse x -> ListOrganizationsResponse
forall x.
ListOrganizationsResponse -> Rep ListOrganizationsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListOrganizationsResponse x -> ListOrganizationsResponse
$cfrom :: forall x.
ListOrganizationsResponse -> Rep ListOrganizationsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListOrganizationsResponse' 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', 'listOrganizationsResponse_nextToken' - The token to use to retrieve the next page of results. The value is
-- \"null\" when there are no more results to return.
--
-- 'organizationSummaries', 'listOrganizationsResponse_organizationSummaries' - The overview of owned organizations presented as a list of organization
-- summaries.
--
-- 'httpStatus', 'listOrganizationsResponse_httpStatus' - The response's http status code.
newListOrganizationsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListOrganizationsResponse
newListOrganizationsResponse :: Int -> ListOrganizationsResponse
newListOrganizationsResponse Int
pHttpStatus_ =
  ListOrganizationsResponse'
    { $sel:nextToken:ListOrganizationsResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:organizationSummaries:ListOrganizationsResponse' :: Maybe [OrganizationSummary]
organizationSummaries = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListOrganizationsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The token to use to retrieve the next page of results. The value is
-- \"null\" when there are no more results to return.
listOrganizationsResponse_nextToken :: Lens.Lens' ListOrganizationsResponse (Prelude.Maybe Prelude.Text)
listOrganizationsResponse_nextToken :: Lens' ListOrganizationsResponse (Maybe Text)
listOrganizationsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOrganizationsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListOrganizationsResponse' :: ListOrganizationsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListOrganizationsResponse
s@ListOrganizationsResponse' {} Maybe Text
a -> ListOrganizationsResponse
s {$sel:nextToken:ListOrganizationsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListOrganizationsResponse)

-- | The overview of owned organizations presented as a list of organization
-- summaries.
listOrganizationsResponse_organizationSummaries :: Lens.Lens' ListOrganizationsResponse (Prelude.Maybe [OrganizationSummary])
listOrganizationsResponse_organizationSummaries :: Lens' ListOrganizationsResponse (Maybe [OrganizationSummary])
listOrganizationsResponse_organizationSummaries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOrganizationsResponse' {Maybe [OrganizationSummary]
organizationSummaries :: Maybe [OrganizationSummary]
$sel:organizationSummaries:ListOrganizationsResponse' :: ListOrganizationsResponse -> Maybe [OrganizationSummary]
organizationSummaries} -> Maybe [OrganizationSummary]
organizationSummaries) (\s :: ListOrganizationsResponse
s@ListOrganizationsResponse' {} Maybe [OrganizationSummary]
a -> ListOrganizationsResponse
s {$sel:organizationSummaries:ListOrganizationsResponse' :: Maybe [OrganizationSummary]
organizationSummaries = Maybe [OrganizationSummary]
a} :: ListOrganizationsResponse) 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.
listOrganizationsResponse_httpStatus :: Lens.Lens' ListOrganizationsResponse Prelude.Int
listOrganizationsResponse_httpStatus :: Lens' ListOrganizationsResponse Int
listOrganizationsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOrganizationsResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListOrganizationsResponse' :: ListOrganizationsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListOrganizationsResponse
s@ListOrganizationsResponse' {} Int
a -> ListOrganizationsResponse
s {$sel:httpStatus:ListOrganizationsResponse' :: Int
httpStatus = Int
a} :: ListOrganizationsResponse)

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