{-# 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.XRay.GetGroups
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves all active group details.
--
-- This operation returns paginated results.
module Amazonka.XRay.GetGroups
  ( -- * Creating a Request
    GetGroups (..),
    newGetGroups,

    -- * Request Lenses
    getGroups_nextToken,

    -- * Destructuring the Response
    GetGroupsResponse (..),
    newGetGroupsResponse,

    -- * Response Lenses
    getGroupsResponse_groups,
    getGroupsResponse_nextToken,
    getGroupsResponse_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.XRay.Types

-- | /See:/ 'newGetGroups' smart constructor.
data GetGroups = GetGroups'
  { -- | Pagination token.
    GetGroups -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (GetGroups -> GetGroups -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetGroups -> GetGroups -> Bool
$c/= :: GetGroups -> GetGroups -> Bool
== :: GetGroups -> GetGroups -> Bool
$c== :: GetGroups -> GetGroups -> Bool
Prelude.Eq, ReadPrec [GetGroups]
ReadPrec GetGroups
Int -> ReadS GetGroups
ReadS [GetGroups]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetGroups]
$creadListPrec :: ReadPrec [GetGroups]
readPrec :: ReadPrec GetGroups
$creadPrec :: ReadPrec GetGroups
readList :: ReadS [GetGroups]
$creadList :: ReadS [GetGroups]
readsPrec :: Int -> ReadS GetGroups
$creadsPrec :: Int -> ReadS GetGroups
Prelude.Read, Int -> GetGroups -> ShowS
[GetGroups] -> ShowS
GetGroups -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetGroups] -> ShowS
$cshowList :: [GetGroups] -> ShowS
show :: GetGroups -> String
$cshow :: GetGroups -> String
showsPrec :: Int -> GetGroups -> ShowS
$cshowsPrec :: Int -> GetGroups -> ShowS
Prelude.Show, forall x. Rep GetGroups x -> GetGroups
forall x. GetGroups -> Rep GetGroups x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetGroups x -> GetGroups
$cfrom :: forall x. GetGroups -> Rep GetGroups x
Prelude.Generic)

-- |
-- Create a value of 'GetGroups' 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', 'getGroups_nextToken' - Pagination token.
newGetGroups ::
  GetGroups
newGetGroups :: GetGroups
newGetGroups =
  GetGroups' {$sel:nextToken:GetGroups' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing}

-- | Pagination token.
getGroups_nextToken :: Lens.Lens' GetGroups (Prelude.Maybe Prelude.Text)
getGroups_nextToken :: Lens' GetGroups (Maybe Text)
getGroups_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetGroups' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetGroups' :: GetGroups -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetGroups
s@GetGroups' {} Maybe Text
a -> GetGroups
s {$sel:nextToken:GetGroups' :: Maybe Text
nextToken = Maybe Text
a} :: GetGroups)

instance Core.AWSPager GetGroups where
  page :: GetGroups -> AWSResponse GetGroups -> Maybe GetGroups
page GetGroups
rq AWSResponse GetGroups
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetGroups
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetGroupsResponse (Maybe Text)
getGroupsResponse_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 GetGroups
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetGroupsResponse (Maybe [GroupSummary])
getGroupsResponse_groups
            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.$ GetGroups
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' GetGroups (Maybe Text)
getGroups_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse GetGroups
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetGroupsResponse (Maybe Text)
getGroupsResponse_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 GetGroups where
  type AWSResponse GetGroups = GetGroupsResponse
  request :: (Service -> Service) -> GetGroups -> Request GetGroups
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 GetGroups
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetGroups)))
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 [GroupSummary] -> Maybe Text -> Int -> GetGroupsResponse
GetGroupsResponse'
            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
"Groups" 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 GetGroups where
  hashWithSalt :: Int -> GetGroups -> Int
hashWithSalt Int
_salt GetGroups' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetGroups' :: GetGroups -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData GetGroups where
  rnf :: GetGroups -> ()
rnf GetGroups' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetGroups' :: GetGroups -> Maybe Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

instance Data.ToHeaders GetGroups where
  toHeaders :: GetGroups -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToJSON GetGroups where
  toJSON :: GetGroups -> Value
toJSON GetGroups' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetGroups' :: GetGroups -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(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 GetGroups where
  toPath :: GetGroups -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/Groups"

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

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

-- |
-- Create a value of 'GetGroupsResponse' 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:
--
-- 'groups', 'getGroupsResponse_groups' - The collection of all active groups.
--
-- 'nextToken', 'getGroupsResponse_nextToken' - Pagination token.
--
-- 'httpStatus', 'getGroupsResponse_httpStatus' - The response's http status code.
newGetGroupsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetGroupsResponse
newGetGroupsResponse :: Int -> GetGroupsResponse
newGetGroupsResponse Int
pHttpStatus_ =
  GetGroupsResponse'
    { $sel:groups:GetGroupsResponse' :: Maybe [GroupSummary]
groups = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetGroupsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetGroupsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The collection of all active groups.
getGroupsResponse_groups :: Lens.Lens' GetGroupsResponse (Prelude.Maybe [GroupSummary])
getGroupsResponse_groups :: Lens' GetGroupsResponse (Maybe [GroupSummary])
getGroupsResponse_groups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetGroupsResponse' {Maybe [GroupSummary]
groups :: Maybe [GroupSummary]
$sel:groups:GetGroupsResponse' :: GetGroupsResponse -> Maybe [GroupSummary]
groups} -> Maybe [GroupSummary]
groups) (\s :: GetGroupsResponse
s@GetGroupsResponse' {} Maybe [GroupSummary]
a -> GetGroupsResponse
s {$sel:groups:GetGroupsResponse' :: Maybe [GroupSummary]
groups = Maybe [GroupSummary]
a} :: GetGroupsResponse) 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

-- | Pagination token.
getGroupsResponse_nextToken :: Lens.Lens' GetGroupsResponse (Prelude.Maybe Prelude.Text)
getGroupsResponse_nextToken :: Lens' GetGroupsResponse (Maybe Text)
getGroupsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetGroupsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetGroupsResponse' :: GetGroupsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetGroupsResponse
s@GetGroupsResponse' {} Maybe Text
a -> GetGroupsResponse
s {$sel:nextToken:GetGroupsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: GetGroupsResponse)

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

instance Prelude.NFData GetGroupsResponse where
  rnf :: GetGroupsResponse -> ()
rnf GetGroupsResponse' {Int
Maybe [GroupSummary]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
groups :: Maybe [GroupSummary]
$sel:httpStatus:GetGroupsResponse' :: GetGroupsResponse -> Int
$sel:nextToken:GetGroupsResponse' :: GetGroupsResponse -> Maybe Text
$sel:groups:GetGroupsResponse' :: GetGroupsResponse -> Maybe [GroupSummary]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [GroupSummary]
groups
      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