{-# 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.MediaStore.ListContainers
-- 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 properties of all containers in AWS Elemental MediaStore.
--
-- You can query to receive all the containers in one response. Or you can
-- include the @MaxResults@ parameter to receive a limited number of
-- containers in each response. In this case, the response includes a
-- token. To get the next set of containers, send the command again, this
-- time with the @NextToken@ parameter (with the returned token as its
-- value). The next set of responses appears, with a token if there are
-- still more containers to receive.
--
-- See also DescribeContainer, which gets the properties of one container.
--
-- This operation returns paginated results.
module Amazonka.MediaStore.ListContainers
  ( -- * Creating a Request
    ListContainers (..),
    newListContainers,

    -- * Request Lenses
    listContainers_maxResults,
    listContainers_nextToken,

    -- * Destructuring the Response
    ListContainersResponse (..),
    newListContainersResponse,

    -- * Response Lenses
    listContainersResponse_nextToken,
    listContainersResponse_httpStatus,
    listContainersResponse_containers,
  )
where

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

-- | /See:/ 'newListContainers' smart constructor.
data ListContainers = ListContainers'
  { -- | Enter the maximum number of containers in the response. Use from 1 to
    -- 255 characters.
    ListContainers -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | Only if you used @MaxResults@ in the first command, enter the token
    -- (which was included in the previous response) to obtain the next set of
    -- containers. This token is included in a response only if there actually
    -- are more containers to list.
    ListContainers -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListContainers -> ListContainers -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListContainers -> ListContainers -> Bool
$c/= :: ListContainers -> ListContainers -> Bool
== :: ListContainers -> ListContainers -> Bool
$c== :: ListContainers -> ListContainers -> Bool
Prelude.Eq, ReadPrec [ListContainers]
ReadPrec ListContainers
Int -> ReadS ListContainers
ReadS [ListContainers]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListContainers]
$creadListPrec :: ReadPrec [ListContainers]
readPrec :: ReadPrec ListContainers
$creadPrec :: ReadPrec ListContainers
readList :: ReadS [ListContainers]
$creadList :: ReadS [ListContainers]
readsPrec :: Int -> ReadS ListContainers
$creadsPrec :: Int -> ReadS ListContainers
Prelude.Read, Int -> ListContainers -> ShowS
[ListContainers] -> ShowS
ListContainers -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListContainers] -> ShowS
$cshowList :: [ListContainers] -> ShowS
show :: ListContainers -> String
$cshow :: ListContainers -> String
showsPrec :: Int -> ListContainers -> ShowS
$cshowsPrec :: Int -> ListContainers -> ShowS
Prelude.Show, forall x. Rep ListContainers x -> ListContainers
forall x. ListContainers -> Rep ListContainers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListContainers x -> ListContainers
$cfrom :: forall x. ListContainers -> Rep ListContainers x
Prelude.Generic)

-- |
-- Create a value of 'ListContainers' 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', 'listContainers_maxResults' - Enter the maximum number of containers in the response. Use from 1 to
-- 255 characters.
--
-- 'nextToken', 'listContainers_nextToken' - Only if you used @MaxResults@ in the first command, enter the token
-- (which was included in the previous response) to obtain the next set of
-- containers. This token is included in a response only if there actually
-- are more containers to list.
newListContainers ::
  ListContainers
newListContainers :: ListContainers
newListContainers =
  ListContainers'
    { $sel:maxResults:ListContainers' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListContainers' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | Enter the maximum number of containers in the response. Use from 1 to
-- 255 characters.
listContainers_maxResults :: Lens.Lens' ListContainers (Prelude.Maybe Prelude.Natural)
listContainers_maxResults :: Lens' ListContainers (Maybe Natural)
listContainers_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListContainers' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListContainers' :: ListContainers -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListContainers
s@ListContainers' {} Maybe Natural
a -> ListContainers
s {$sel:maxResults:ListContainers' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListContainers)

-- | Only if you used @MaxResults@ in the first command, enter the token
-- (which was included in the previous response) to obtain the next set of
-- containers. This token is included in a response only if there actually
-- are more containers to list.
listContainers_nextToken :: Lens.Lens' ListContainers (Prelude.Maybe Prelude.Text)
listContainers_nextToken :: Lens' ListContainers (Maybe Text)
listContainers_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListContainers' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListContainers' :: ListContainers -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListContainers
s@ListContainers' {} Maybe Text
a -> ListContainers
s {$sel:nextToken:ListContainers' :: Maybe Text
nextToken = Maybe Text
a} :: ListContainers)

instance Core.AWSPager ListContainers where
  page :: ListContainers
-> AWSResponse ListContainers -> Maybe ListContainers
page ListContainers
rq AWSResponse ListContainers
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListContainers
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListContainersResponse (Maybe Text)
listContainersResponse_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 ListContainers
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' ListContainersResponse [Container]
listContainersResponse_containers) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListContainers
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListContainers (Maybe Text)
listContainers_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListContainers
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListContainersResponse (Maybe Text)
listContainersResponse_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 ListContainers where
  type
    AWSResponse ListContainers =
      ListContainersResponse
  request :: (Service -> Service) -> ListContainers -> Request ListContainers
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 ListContainers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListContainers)))
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 -> Int -> [Container] -> ListContainersResponse
ListContainersResponse'
            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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            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
"Containers" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ListContainers where
  hashWithSalt :: Int -> ListContainers -> Int
hashWithSalt Int
_salt ListContainers' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListContainers' :: ListContainers -> Maybe Text
$sel:maxResults:ListContainers' :: ListContainers -> 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 ListContainers where
  rnf :: ListContainers -> ()
rnf ListContainers' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListContainers' :: ListContainers -> Maybe Text
$sel:maxResults:ListContainers' :: ListContainers -> 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 ListContainers where
  toHeaders :: ListContainers -> 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
"MediaStore_20170901.ListContainers" ::
                          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 ListContainers where
  toJSON :: ListContainers -> Value
toJSON ListContainers' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListContainers' :: ListContainers -> Maybe Text
$sel:maxResults:ListContainers' :: ListContainers -> 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 ListContainers where
  toPath :: ListContainers -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListContainersResponse' smart constructor.
data ListContainersResponse = ListContainersResponse'
  { -- | @NextToken@ is the token to use in the next call to @ListContainers@.
    -- This token is returned only if you included the @MaxResults@ tag in the
    -- original command, and only if there are still containers to return.
    ListContainersResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListContainersResponse -> Int
httpStatus :: Prelude.Int,
    -- | The names of the containers.
    ListContainersResponse -> [Container]
containers :: [Container]
  }
  deriving (ListContainersResponse -> ListContainersResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListContainersResponse -> ListContainersResponse -> Bool
$c/= :: ListContainersResponse -> ListContainersResponse -> Bool
== :: ListContainersResponse -> ListContainersResponse -> Bool
$c== :: ListContainersResponse -> ListContainersResponse -> Bool
Prelude.Eq, ReadPrec [ListContainersResponse]
ReadPrec ListContainersResponse
Int -> ReadS ListContainersResponse
ReadS [ListContainersResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListContainersResponse]
$creadListPrec :: ReadPrec [ListContainersResponse]
readPrec :: ReadPrec ListContainersResponse
$creadPrec :: ReadPrec ListContainersResponse
readList :: ReadS [ListContainersResponse]
$creadList :: ReadS [ListContainersResponse]
readsPrec :: Int -> ReadS ListContainersResponse
$creadsPrec :: Int -> ReadS ListContainersResponse
Prelude.Read, Int -> ListContainersResponse -> ShowS
[ListContainersResponse] -> ShowS
ListContainersResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListContainersResponse] -> ShowS
$cshowList :: [ListContainersResponse] -> ShowS
show :: ListContainersResponse -> String
$cshow :: ListContainersResponse -> String
showsPrec :: Int -> ListContainersResponse -> ShowS
$cshowsPrec :: Int -> ListContainersResponse -> ShowS
Prelude.Show, forall x. Rep ListContainersResponse x -> ListContainersResponse
forall x. ListContainersResponse -> Rep ListContainersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListContainersResponse x -> ListContainersResponse
$cfrom :: forall x. ListContainersResponse -> Rep ListContainersResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListContainersResponse' 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', 'listContainersResponse_nextToken' - @NextToken@ is the token to use in the next call to @ListContainers@.
-- This token is returned only if you included the @MaxResults@ tag in the
-- original command, and only if there are still containers to return.
--
-- 'httpStatus', 'listContainersResponse_httpStatus' - The response's http status code.
--
-- 'containers', 'listContainersResponse_containers' - The names of the containers.
newListContainersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListContainersResponse
newListContainersResponse :: Int -> ListContainersResponse
newListContainersResponse Int
pHttpStatus_ =
  ListContainersResponse'
    { $sel:nextToken:ListContainersResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListContainersResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:containers:ListContainersResponse' :: [Container]
containers = forall a. Monoid a => a
Prelude.mempty
    }

-- | @NextToken@ is the token to use in the next call to @ListContainers@.
-- This token is returned only if you included the @MaxResults@ tag in the
-- original command, and only if there are still containers to return.
listContainersResponse_nextToken :: Lens.Lens' ListContainersResponse (Prelude.Maybe Prelude.Text)
listContainersResponse_nextToken :: Lens' ListContainersResponse (Maybe Text)
listContainersResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListContainersResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListContainersResponse' :: ListContainersResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListContainersResponse
s@ListContainersResponse' {} Maybe Text
a -> ListContainersResponse
s {$sel:nextToken:ListContainersResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListContainersResponse)

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

-- | The names of the containers.
listContainersResponse_containers :: Lens.Lens' ListContainersResponse [Container]
listContainersResponse_containers :: Lens' ListContainersResponse [Container]
listContainersResponse_containers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListContainersResponse' {[Container]
containers :: [Container]
$sel:containers:ListContainersResponse' :: ListContainersResponse -> [Container]
containers} -> [Container]
containers) (\s :: ListContainersResponse
s@ListContainersResponse' {} [Container]
a -> ListContainersResponse
s {$sel:containers:ListContainersResponse' :: [Container]
containers = [Container]
a} :: ListContainersResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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