{-# 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.StartModel
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Starts the running of the version of an Amazon Lookout for Vision model.
-- Starting a model takes a while to complete. To check the current state
-- of the model, use DescribeModel.
--
-- A model is ready to use when its status is @HOSTED@.
--
-- Once the model is running, you can detect custom labels in new images by
-- calling DetectAnomalies.
--
-- You are charged for the amount of time that the model is running. To
-- stop a running model, call StopModel.
--
-- This operation requires permissions to perform the
-- @lookoutvision:StartModel@ operation.
module Amazonka.LookoutVision.StartModel
  ( -- * Creating a Request
    StartModel (..),
    newStartModel,

    -- * Request Lenses
    startModel_clientToken,
    startModel_projectName,
    startModel_modelVersion,
    startModel_minInferenceUnits,

    -- * Destructuring the Response
    StartModelResponse (..),
    newStartModelResponse,

    -- * Response Lenses
    startModelResponse_status,
    startModelResponse_httpStatus,
  )
where

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

-- | /See:/ 'newStartModel' smart constructor.
data StartModel = StartModel'
  { -- | ClientToken is an idempotency token that ensures a call to @StartModel@
    -- completes only once. You choose the value to pass. For example, An
    -- issue, such as an network outage, might prevent you from getting a
    -- response from @StartModel@. In this case, safely retry your call to
    -- @StartModel@ by using the same @ClientToken@ parameter value. An error
    -- occurs if the other input parameters are not the same as in the first
    -- request. Using a different value for @ClientToken@ is considered a new
    -- call to @StartModel@. An idempotency token is active for 8 hours.
    StartModel -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the project that contains the model that you want to start.
    StartModel -> Text
projectName :: Prelude.Text,
    -- | The version of the model that you want to start.
    StartModel -> Text
modelVersion :: Prelude.Text,
    -- | The minimum number of inference units to use. A single inference unit
    -- represents 1 hour of processing and can support up to 5 Transaction Pers
    -- Second (TPS). Use a higher number to increase the TPS throughput of your
    -- model. You are charged for the number of inference units that you use.
    StartModel -> Natural
minInferenceUnits :: Prelude.Natural
  }
  deriving (StartModel -> StartModel -> Bool
(StartModel -> StartModel -> Bool)
-> (StartModel -> StartModel -> Bool) -> Eq StartModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartModel -> StartModel -> Bool
$c/= :: StartModel -> StartModel -> Bool
== :: StartModel -> StartModel -> Bool
$c== :: StartModel -> StartModel -> Bool
Prelude.Eq, ReadPrec [StartModel]
ReadPrec StartModel
Int -> ReadS StartModel
ReadS [StartModel]
(Int -> ReadS StartModel)
-> ReadS [StartModel]
-> ReadPrec StartModel
-> ReadPrec [StartModel]
-> Read StartModel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartModel]
$creadListPrec :: ReadPrec [StartModel]
readPrec :: ReadPrec StartModel
$creadPrec :: ReadPrec StartModel
readList :: ReadS [StartModel]
$creadList :: ReadS [StartModel]
readsPrec :: Int -> ReadS StartModel
$creadsPrec :: Int -> ReadS StartModel
Prelude.Read, Int -> StartModel -> ShowS
[StartModel] -> ShowS
StartModel -> String
(Int -> StartModel -> ShowS)
-> (StartModel -> String)
-> ([StartModel] -> ShowS)
-> Show StartModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartModel] -> ShowS
$cshowList :: [StartModel] -> ShowS
show :: StartModel -> String
$cshow :: StartModel -> String
showsPrec :: Int -> StartModel -> ShowS
$cshowsPrec :: Int -> StartModel -> ShowS
Prelude.Show, (forall x. StartModel -> Rep StartModel x)
-> (forall x. Rep StartModel x -> StartModel) -> Generic StartModel
forall x. Rep StartModel x -> StartModel
forall x. StartModel -> Rep StartModel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartModel x -> StartModel
$cfrom :: forall x. StartModel -> Rep StartModel x
Prelude.Generic)

-- |
-- Create a value of 'StartModel' 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:
--
-- 'clientToken', 'startModel_clientToken' - ClientToken is an idempotency token that ensures a call to @StartModel@
-- completes only once. You choose the value to pass. For example, An
-- issue, such as an network outage, might prevent you from getting a
-- response from @StartModel@. In this case, safely retry your call to
-- @StartModel@ by using the same @ClientToken@ parameter value. An error
-- occurs if the other input parameters are not the same as in the first
-- request. Using a different value for @ClientToken@ is considered a new
-- call to @StartModel@. An idempotency token is active for 8 hours.
--
-- 'projectName', 'startModel_projectName' - The name of the project that contains the model that you want to start.
--
-- 'modelVersion', 'startModel_modelVersion' - The version of the model that you want to start.
--
-- 'minInferenceUnits', 'startModel_minInferenceUnits' - The minimum number of inference units to use. A single inference unit
-- represents 1 hour of processing and can support up to 5 Transaction Pers
-- Second (TPS). Use a higher number to increase the TPS throughput of your
-- model. You are charged for the number of inference units that you use.
newStartModel ::
  -- | 'projectName'
  Prelude.Text ->
  -- | 'modelVersion'
  Prelude.Text ->
  -- | 'minInferenceUnits'
  Prelude.Natural ->
  StartModel
newStartModel :: Text -> Text -> Natural -> StartModel
newStartModel
  Text
pProjectName_
  Text
pModelVersion_
  Natural
pMinInferenceUnits_ =
    StartModel' :: Maybe Text -> Text -> Text -> Natural -> StartModel
StartModel'
      { $sel:clientToken:StartModel' :: Maybe Text
clientToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:projectName:StartModel' :: Text
projectName = Text
pProjectName_,
        $sel:modelVersion:StartModel' :: Text
modelVersion = Text
pModelVersion_,
        $sel:minInferenceUnits:StartModel' :: Natural
minInferenceUnits = Natural
pMinInferenceUnits_
      }

-- | ClientToken is an idempotency token that ensures a call to @StartModel@
-- completes only once. You choose the value to pass. For example, An
-- issue, such as an network outage, might prevent you from getting a
-- response from @StartModel@. In this case, safely retry your call to
-- @StartModel@ by using the same @ClientToken@ parameter value. An error
-- occurs if the other input parameters are not the same as in the first
-- request. Using a different value for @ClientToken@ is considered a new
-- call to @StartModel@. An idempotency token is active for 8 hours.
startModel_clientToken :: Lens.Lens' StartModel (Prelude.Maybe Prelude.Text)
startModel_clientToken :: (Maybe Text -> f (Maybe Text)) -> StartModel -> f StartModel
startModel_clientToken = (StartModel -> Maybe Text)
-> (StartModel -> Maybe Text -> StartModel)
-> Lens StartModel StartModel (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartModel' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:StartModel' :: StartModel -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: StartModel
s@StartModel' {} Maybe Text
a -> StartModel
s {$sel:clientToken:StartModel' :: Maybe Text
clientToken = Maybe Text
a} :: StartModel)

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

-- | The version of the model that you want to start.
startModel_modelVersion :: Lens.Lens' StartModel Prelude.Text
startModel_modelVersion :: (Text -> f Text) -> StartModel -> f StartModel
startModel_modelVersion = (StartModel -> Text)
-> (StartModel -> Text -> StartModel)
-> Lens StartModel StartModel Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartModel' {Text
modelVersion :: Text
$sel:modelVersion:StartModel' :: StartModel -> Text
modelVersion} -> Text
modelVersion) (\s :: StartModel
s@StartModel' {} Text
a -> StartModel
s {$sel:modelVersion:StartModel' :: Text
modelVersion = Text
a} :: StartModel)

-- | The minimum number of inference units to use. A single inference unit
-- represents 1 hour of processing and can support up to 5 Transaction Pers
-- Second (TPS). Use a higher number to increase the TPS throughput of your
-- model. You are charged for the number of inference units that you use.
startModel_minInferenceUnits :: Lens.Lens' StartModel Prelude.Natural
startModel_minInferenceUnits :: (Natural -> f Natural) -> StartModel -> f StartModel
startModel_minInferenceUnits = (StartModel -> Natural)
-> (StartModel -> Natural -> StartModel)
-> Lens StartModel StartModel Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartModel' {Natural
minInferenceUnits :: Natural
$sel:minInferenceUnits:StartModel' :: StartModel -> Natural
minInferenceUnits} -> Natural
minInferenceUnits) (\s :: StartModel
s@StartModel' {} Natural
a -> StartModel
s {$sel:minInferenceUnits:StartModel' :: Natural
minInferenceUnits = Natural
a} :: StartModel)

instance Core.AWSRequest StartModel where
  type AWSResponse StartModel = StartModelResponse
  request :: StartModel -> Request StartModel
request = Service -> StartModel -> Request StartModel
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartModel)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartModel))
-> Logger
-> Service
-> Proxy StartModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartModel)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe ModelHostingStatus -> Int -> StartModelResponse
StartModelResponse'
            (Maybe ModelHostingStatus -> Int -> StartModelResponse)
-> Either String (Maybe ModelHostingStatus)
-> Either String (Int -> StartModelResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe ModelHostingStatus)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Status")
            Either String (Int -> StartModelResponse)
-> Either String Int -> Either String StartModelResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable StartModel

instance Prelude.NFData StartModel

instance Core.ToHeaders StartModel where
  toHeaders :: StartModel -> ResponseHeaders
toHeaders StartModel' {Natural
Maybe Text
Text
minInferenceUnits :: Natural
modelVersion :: Text
projectName :: Text
clientToken :: Maybe Text
$sel:minInferenceUnits:StartModel' :: StartModel -> Natural
$sel:modelVersion:StartModel' :: StartModel -> Text
$sel:projectName:StartModel' :: StartModel -> Text
$sel:clientToken:StartModel' :: StartModel -> Maybe Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"X-Amzn-Client-Token" HeaderName -> Maybe Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Maybe Text
clientToken,
        HeaderName
"Content-Type"
          HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"application/x-amz-json-1.1" :: Prelude.ByteString)
      ]

instance Core.ToJSON StartModel where
  toJSON :: StartModel -> Value
toJSON StartModel' {Natural
Maybe Text
Text
minInferenceUnits :: Natural
modelVersion :: Text
projectName :: Text
clientToken :: Maybe Text
$sel:minInferenceUnits:StartModel' :: StartModel -> Natural
$sel:modelVersion:StartModel' :: StartModel -> Text
$sel:projectName:StartModel' :: StartModel -> Text
$sel:clientToken:StartModel' :: StartModel -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"MinInferenceUnits" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
minInferenceUnits)
          ]
      )

instance Core.ToPath StartModel where
  toPath :: StartModel -> ByteString
toPath StartModel' {Natural
Maybe Text
Text
minInferenceUnits :: Natural
modelVersion :: Text
projectName :: Text
clientToken :: Maybe Text
$sel:minInferenceUnits:StartModel' :: StartModel -> Natural
$sel:modelVersion:StartModel' :: StartModel -> Text
$sel:projectName:StartModel' :: StartModel -> Text
$sel:clientToken:StartModel' :: StartModel -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2020-11-20/projects/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
projectName,
        ByteString
"/models/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
modelVersion,
        ByteString
"/start"
      ]

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

-- | /See:/ 'newStartModelResponse' smart constructor.
data StartModelResponse = StartModelResponse'
  { -- | The current running status of the model.
    StartModelResponse -> Maybe ModelHostingStatus
status :: Prelude.Maybe ModelHostingStatus,
    -- | The response's http status code.
    StartModelResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartModelResponse -> StartModelResponse -> Bool
(StartModelResponse -> StartModelResponse -> Bool)
-> (StartModelResponse -> StartModelResponse -> Bool)
-> Eq StartModelResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartModelResponse -> StartModelResponse -> Bool
$c/= :: StartModelResponse -> StartModelResponse -> Bool
== :: StartModelResponse -> StartModelResponse -> Bool
$c== :: StartModelResponse -> StartModelResponse -> Bool
Prelude.Eq, ReadPrec [StartModelResponse]
ReadPrec StartModelResponse
Int -> ReadS StartModelResponse
ReadS [StartModelResponse]
(Int -> ReadS StartModelResponse)
-> ReadS [StartModelResponse]
-> ReadPrec StartModelResponse
-> ReadPrec [StartModelResponse]
-> Read StartModelResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartModelResponse]
$creadListPrec :: ReadPrec [StartModelResponse]
readPrec :: ReadPrec StartModelResponse
$creadPrec :: ReadPrec StartModelResponse
readList :: ReadS [StartModelResponse]
$creadList :: ReadS [StartModelResponse]
readsPrec :: Int -> ReadS StartModelResponse
$creadsPrec :: Int -> ReadS StartModelResponse
Prelude.Read, Int -> StartModelResponse -> ShowS
[StartModelResponse] -> ShowS
StartModelResponse -> String
(Int -> StartModelResponse -> ShowS)
-> (StartModelResponse -> String)
-> ([StartModelResponse] -> ShowS)
-> Show StartModelResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartModelResponse] -> ShowS
$cshowList :: [StartModelResponse] -> ShowS
show :: StartModelResponse -> String
$cshow :: StartModelResponse -> String
showsPrec :: Int -> StartModelResponse -> ShowS
$cshowsPrec :: Int -> StartModelResponse -> ShowS
Prelude.Show, (forall x. StartModelResponse -> Rep StartModelResponse x)
-> (forall x. Rep StartModelResponse x -> StartModelResponse)
-> Generic StartModelResponse
forall x. Rep StartModelResponse x -> StartModelResponse
forall x. StartModelResponse -> Rep StartModelResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartModelResponse x -> StartModelResponse
$cfrom :: forall x. StartModelResponse -> Rep StartModelResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartModelResponse' 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:
--
-- 'status', 'startModelResponse_status' - The current running status of the model.
--
-- 'httpStatus', 'startModelResponse_httpStatus' - The response's http status code.
newStartModelResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartModelResponse
newStartModelResponse :: Int -> StartModelResponse
newStartModelResponse Int
pHttpStatus_ =
  StartModelResponse' :: Maybe ModelHostingStatus -> Int -> StartModelResponse
StartModelResponse'
    { $sel:status:StartModelResponse' :: Maybe ModelHostingStatus
status = Maybe ModelHostingStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartModelResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The current running status of the model.
startModelResponse_status :: Lens.Lens' StartModelResponse (Prelude.Maybe ModelHostingStatus)
startModelResponse_status :: (Maybe ModelHostingStatus -> f (Maybe ModelHostingStatus))
-> StartModelResponse -> f StartModelResponse
startModelResponse_status = (StartModelResponse -> Maybe ModelHostingStatus)
-> (StartModelResponse
    -> Maybe ModelHostingStatus -> StartModelResponse)
-> Lens
     StartModelResponse
     StartModelResponse
     (Maybe ModelHostingStatus)
     (Maybe ModelHostingStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartModelResponse' {Maybe ModelHostingStatus
status :: Maybe ModelHostingStatus
$sel:status:StartModelResponse' :: StartModelResponse -> Maybe ModelHostingStatus
status} -> Maybe ModelHostingStatus
status) (\s :: StartModelResponse
s@StartModelResponse' {} Maybe ModelHostingStatus
a -> StartModelResponse
s {$sel:status:StartModelResponse' :: Maybe ModelHostingStatus
status = Maybe ModelHostingStatus
a} :: StartModelResponse)

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

instance Prelude.NFData StartModelResponse