{-# 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.LookoutVision.ListModels
-- 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 versions of a model in an Amazon Lookout for Vision project.
--
-- The @ListModels@ operation is eventually consistent. Recent calls to
-- @CreateModel@ might take a while to appear in the response from
-- @ListProjects@.
--
-- This operation requires permissions to perform the
-- @lookoutvision:ListModels@ operation.
--
-- This operation returns paginated results.
module Amazonka.LookoutVision.ListModels
  ( -- * Creating a Request
    ListModels (..),
    newListModels,

    -- * Request Lenses
    listModels_maxResults,
    listModels_nextToken,
    listModels_projectName,

    -- * Destructuring the Response
    ListModelsResponse (..),
    newListModelsResponse,

    -- * Response Lenses
    listModelsResponse_models,
    listModelsResponse_nextToken,
    listModelsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListModels' smart constructor.
data ListModels = ListModels'
  { -- | The maximum number of results to return per paginated call. The largest
    -- value you can specify is 100. If you specify a value greater than 100, a
    -- ValidationException error occurs. The default value is 100.
    ListModels -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | If the previous response was incomplete (because there is more data to
    -- retrieve), Amazon Lookout for Vision returns a pagination token in the
    -- response. You can use this pagination token to retrieve the next set of
    -- models.
    ListModels -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the project that contains the model versions that you want
    -- to list.
    ListModels -> Text
projectName :: Prelude.Text
  }
  deriving (ListModels -> ListModels -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListModels -> ListModels -> Bool
$c/= :: ListModels -> ListModels -> Bool
== :: ListModels -> ListModels -> Bool
$c== :: ListModels -> ListModels -> Bool
Prelude.Eq, ReadPrec [ListModels]
ReadPrec ListModels
Int -> ReadS ListModels
ReadS [ListModels]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListModels]
$creadListPrec :: ReadPrec [ListModels]
readPrec :: ReadPrec ListModels
$creadPrec :: ReadPrec ListModels
readList :: ReadS [ListModels]
$creadList :: ReadS [ListModels]
readsPrec :: Int -> ReadS ListModels
$creadsPrec :: Int -> ReadS ListModels
Prelude.Read, Int -> ListModels -> ShowS
[ListModels] -> ShowS
ListModels -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListModels] -> ShowS
$cshowList :: [ListModels] -> ShowS
show :: ListModels -> String
$cshow :: ListModels -> String
showsPrec :: Int -> ListModels -> ShowS
$cshowsPrec :: Int -> ListModels -> ShowS
Prelude.Show, forall x. Rep ListModels x -> ListModels
forall x. ListModels -> Rep ListModels x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListModels x -> ListModels
$cfrom :: forall x. ListModels -> Rep ListModels x
Prelude.Generic)

-- |
-- Create a value of 'ListModels' 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', 'listModels_maxResults' - The maximum number of results to return per paginated call. The largest
-- value you can specify is 100. If you specify a value greater than 100, a
-- ValidationException error occurs. The default value is 100.
--
-- 'nextToken', 'listModels_nextToken' - If the previous response was incomplete (because there is more data to
-- retrieve), Amazon Lookout for Vision returns a pagination token in the
-- response. You can use this pagination token to retrieve the next set of
-- models.
--
-- 'projectName', 'listModels_projectName' - The name of the project that contains the model versions that you want
-- to list.
newListModels ::
  -- | 'projectName'
  Prelude.Text ->
  ListModels
newListModels :: Text -> ListModels
newListModels Text
pProjectName_ =
  ListModels'
    { $sel:maxResults:ListModels' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListModels' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:projectName:ListModels' :: Text
projectName = Text
pProjectName_
    }

-- | The maximum number of results to return per paginated call. The largest
-- value you can specify is 100. If you specify a value greater than 100, a
-- ValidationException error occurs. The default value is 100.
listModels_maxResults :: Lens.Lens' ListModels (Prelude.Maybe Prelude.Natural)
listModels_maxResults :: Lens' ListModels (Maybe Natural)
listModels_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListModels' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListModels' :: ListModels -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListModels
s@ListModels' {} Maybe Natural
a -> ListModels
s {$sel:maxResults:ListModels' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListModels)

-- | If the previous response was incomplete (because there is more data to
-- retrieve), Amazon Lookout for Vision returns a pagination token in the
-- response. You can use this pagination token to retrieve the next set of
-- models.
listModels_nextToken :: Lens.Lens' ListModels (Prelude.Maybe Prelude.Text)
listModels_nextToken :: Lens' ListModels (Maybe Text)
listModels_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListModels' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListModels' :: ListModels -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListModels
s@ListModels' {} Maybe Text
a -> ListModels
s {$sel:nextToken:ListModels' :: Maybe Text
nextToken = Maybe Text
a} :: ListModels)

-- | The name of the project that contains the model versions that you want
-- to list.
listModels_projectName :: Lens.Lens' ListModels Prelude.Text
listModels_projectName :: Lens' ListModels Text
listModels_projectName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListModels' {Text
projectName :: Text
$sel:projectName:ListModels' :: ListModels -> Text
projectName} -> Text
projectName) (\s :: ListModels
s@ListModels' {} Text
a -> ListModels
s {$sel:projectName:ListModels' :: Text
projectName = Text
a} :: ListModels)

instance Core.AWSPager ListModels where
  page :: ListModels -> AWSResponse ListModels -> Maybe ListModels
page ListModels
rq AWSResponse ListModels
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListModels
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListModelsResponse (Maybe Text)
listModelsResponse_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 ListModels
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListModelsResponse (Maybe [ModelMetadata])
listModelsResponse_models
            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.$ ListModels
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListModels (Maybe Text)
listModels_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListModels
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListModelsResponse (Maybe Text)
listModelsResponse_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 ListModels where
  type AWSResponse ListModels = ListModelsResponse
  request :: (Service -> Service) -> ListModels -> Request ListModels
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListModels
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListModels)))
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 [ModelMetadata] -> Maybe Text -> Int -> ListModelsResponse
ListModelsResponse'
            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
"Models" 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 ListModels where
  hashWithSalt :: Int -> ListModels -> Int
hashWithSalt Int
_salt ListModels' {Maybe Natural
Maybe Text
Text
projectName :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:projectName:ListModels' :: ListModels -> Text
$sel:nextToken:ListModels' :: ListModels -> Maybe Text
$sel:maxResults:ListModels' :: ListModels -> 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
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
projectName

instance Prelude.NFData ListModels where
  rnf :: ListModels -> ()
rnf ListModels' {Maybe Natural
Maybe Text
Text
projectName :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:projectName:ListModels' :: ListModels -> Text
$sel:nextToken:ListModels' :: ListModels -> Maybe Text
$sel:maxResults:ListModels' :: ListModels -> 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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
projectName

instance Data.ToHeaders ListModels where
  toHeaders :: ListModels -> 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.ToPath ListModels where
  toPath :: ListModels -> ByteString
toPath ListModels' {Maybe Natural
Maybe Text
Text
projectName :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:projectName:ListModels' :: ListModels -> Text
$sel:nextToken:ListModels' :: ListModels -> Maybe Text
$sel:maxResults:ListModels' :: ListModels -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2020-11-20/projects/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
projectName,
        ByteString
"/models"
      ]

instance Data.ToQuery ListModels where
  toQuery :: ListModels -> QueryString
toQuery ListModels' {Maybe Natural
Maybe Text
Text
projectName :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:projectName:ListModels' :: ListModels -> Text
$sel:nextToken:ListModels' :: ListModels -> Maybe Text
$sel:maxResults:ListModels' :: ListModels -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"maxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxResults,
        ByteString
"nextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | /See:/ 'newListModelsResponse' smart constructor.
data ListModelsResponse = ListModelsResponse'
  { -- | A list of model versions in the specified project.
    ListModelsResponse -> Maybe [ModelMetadata]
models :: Prelude.Maybe [ModelMetadata],
    -- | If the response is truncated, Amazon Lookout for Vision returns this
    -- token that you can use in the subsequent request to retrieve the next
    -- set of models.
    ListModelsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListModelsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListModelsResponse -> ListModelsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListModelsResponse -> ListModelsResponse -> Bool
$c/= :: ListModelsResponse -> ListModelsResponse -> Bool
== :: ListModelsResponse -> ListModelsResponse -> Bool
$c== :: ListModelsResponse -> ListModelsResponse -> Bool
Prelude.Eq, ReadPrec [ListModelsResponse]
ReadPrec ListModelsResponse
Int -> ReadS ListModelsResponse
ReadS [ListModelsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListModelsResponse]
$creadListPrec :: ReadPrec [ListModelsResponse]
readPrec :: ReadPrec ListModelsResponse
$creadPrec :: ReadPrec ListModelsResponse
readList :: ReadS [ListModelsResponse]
$creadList :: ReadS [ListModelsResponse]
readsPrec :: Int -> ReadS ListModelsResponse
$creadsPrec :: Int -> ReadS ListModelsResponse
Prelude.Read, Int -> ListModelsResponse -> ShowS
[ListModelsResponse] -> ShowS
ListModelsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListModelsResponse] -> ShowS
$cshowList :: [ListModelsResponse] -> ShowS
show :: ListModelsResponse -> String
$cshow :: ListModelsResponse -> String
showsPrec :: Int -> ListModelsResponse -> ShowS
$cshowsPrec :: Int -> ListModelsResponse -> ShowS
Prelude.Show, forall x. Rep ListModelsResponse x -> ListModelsResponse
forall x. ListModelsResponse -> Rep ListModelsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListModelsResponse x -> ListModelsResponse
$cfrom :: forall x. ListModelsResponse -> Rep ListModelsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListModelsResponse' 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:
--
-- 'models', 'listModelsResponse_models' - A list of model versions in the specified project.
--
-- 'nextToken', 'listModelsResponse_nextToken' - If the response is truncated, Amazon Lookout for Vision returns this
-- token that you can use in the subsequent request to retrieve the next
-- set of models.
--
-- 'httpStatus', 'listModelsResponse_httpStatus' - The response's http status code.
newListModelsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListModelsResponse
newListModelsResponse :: Int -> ListModelsResponse
newListModelsResponse Int
pHttpStatus_ =
  ListModelsResponse'
    { $sel:models:ListModelsResponse' :: Maybe [ModelMetadata]
models = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListModelsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListModelsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of model versions in the specified project.
listModelsResponse_models :: Lens.Lens' ListModelsResponse (Prelude.Maybe [ModelMetadata])
listModelsResponse_models :: Lens' ListModelsResponse (Maybe [ModelMetadata])
listModelsResponse_models = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListModelsResponse' {Maybe [ModelMetadata]
models :: Maybe [ModelMetadata]
$sel:models:ListModelsResponse' :: ListModelsResponse -> Maybe [ModelMetadata]
models} -> Maybe [ModelMetadata]
models) (\s :: ListModelsResponse
s@ListModelsResponse' {} Maybe [ModelMetadata]
a -> ListModelsResponse
s {$sel:models:ListModelsResponse' :: Maybe [ModelMetadata]
models = Maybe [ModelMetadata]
a} :: ListModelsResponse) 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 the response is truncated, Amazon Lookout for Vision returns this
-- token that you can use in the subsequent request to retrieve the next
-- set of models.
listModelsResponse_nextToken :: Lens.Lens' ListModelsResponse (Prelude.Maybe Prelude.Text)
listModelsResponse_nextToken :: Lens' ListModelsResponse (Maybe Text)
listModelsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListModelsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListModelsResponse' :: ListModelsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListModelsResponse
s@ListModelsResponse' {} Maybe Text
a -> ListModelsResponse
s {$sel:nextToken:ListModelsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListModelsResponse)

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

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