{-# 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.StopModel
-- 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)
--
-- Stops the hosting of a running model. The operation might take a while
-- to complete. To check the current status, call DescribeModel.
--
-- After the model hosting stops, the @Status@ of the model is @TRAINED@.
--
-- This operation requires permissions to perform the
-- @lookoutvision:StopModel@ operation.
module Amazonka.LookoutVision.StopModel
  ( -- * Creating a Request
    StopModel (..),
    newStopModel,

    -- * Request Lenses
    stopModel_clientToken,
    stopModel_projectName,
    stopModel_modelVersion,

    -- * Destructuring the Response
    StopModelResponse (..),
    newStopModelResponse,

    -- * Response Lenses
    stopModelResponse_status,
    stopModelResponse_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:/ 'newStopModel' smart constructor.
data StopModel = StopModel'
  { -- | ClientToken is an idempotency token that ensures a call to @StopModel@
    -- 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 @StopModel@. In this case, safely retry your call to
    -- @StopModel@ 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 @StopModel@. An idempotency token is active for 8 hours.
    StopModel -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the project that contains the model that you want to stop.
    StopModel -> Text
projectName :: Prelude.Text,
    -- | The version of the model that you want to stop.
    StopModel -> Text
modelVersion :: Prelude.Text
  }
  deriving (StopModel -> StopModel -> Bool
(StopModel -> StopModel -> Bool)
-> (StopModel -> StopModel -> Bool) -> Eq StopModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopModel -> StopModel -> Bool
$c/= :: StopModel -> StopModel -> Bool
== :: StopModel -> StopModel -> Bool
$c== :: StopModel -> StopModel -> Bool
Prelude.Eq, ReadPrec [StopModel]
ReadPrec StopModel
Int -> ReadS StopModel
ReadS [StopModel]
(Int -> ReadS StopModel)
-> ReadS [StopModel]
-> ReadPrec StopModel
-> ReadPrec [StopModel]
-> Read StopModel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopModel]
$creadListPrec :: ReadPrec [StopModel]
readPrec :: ReadPrec StopModel
$creadPrec :: ReadPrec StopModel
readList :: ReadS [StopModel]
$creadList :: ReadS [StopModel]
readsPrec :: Int -> ReadS StopModel
$creadsPrec :: Int -> ReadS StopModel
Prelude.Read, Int -> StopModel -> ShowS
[StopModel] -> ShowS
StopModel -> String
(Int -> StopModel -> ShowS)
-> (StopModel -> String)
-> ([StopModel] -> ShowS)
-> Show StopModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopModel] -> ShowS
$cshowList :: [StopModel] -> ShowS
show :: StopModel -> String
$cshow :: StopModel -> String
showsPrec :: Int -> StopModel -> ShowS
$cshowsPrec :: Int -> StopModel -> ShowS
Prelude.Show, (forall x. StopModel -> Rep StopModel x)
-> (forall x. Rep StopModel x -> StopModel) -> Generic StopModel
forall x. Rep StopModel x -> StopModel
forall x. StopModel -> Rep StopModel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopModel x -> StopModel
$cfrom :: forall x. StopModel -> Rep StopModel x
Prelude.Generic)

-- |
-- Create a value of 'StopModel' 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', 'stopModel_clientToken' - ClientToken is an idempotency token that ensures a call to @StopModel@
-- 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 @StopModel@. In this case, safely retry your call to
-- @StopModel@ 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 @StopModel@. An idempotency token is active for 8 hours.
--
-- 'projectName', 'stopModel_projectName' - The name of the project that contains the model that you want to stop.
--
-- 'modelVersion', 'stopModel_modelVersion' - The version of the model that you want to stop.
newStopModel ::
  -- | 'projectName'
  Prelude.Text ->
  -- | 'modelVersion'
  Prelude.Text ->
  StopModel
newStopModel :: Text -> Text -> StopModel
newStopModel Text
pProjectName_ Text
pModelVersion_ =
  StopModel' :: Maybe Text -> Text -> Text -> StopModel
StopModel'
    { $sel:clientToken:StopModel' :: Maybe Text
clientToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:projectName:StopModel' :: Text
projectName = Text
pProjectName_,
      $sel:modelVersion:StopModel' :: Text
modelVersion = Text
pModelVersion_
    }

-- | ClientToken is an idempotency token that ensures a call to @StopModel@
-- 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 @StopModel@. In this case, safely retry your call to
-- @StopModel@ 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 @StopModel@. An idempotency token is active for 8 hours.
stopModel_clientToken :: Lens.Lens' StopModel (Prelude.Maybe Prelude.Text)
stopModel_clientToken :: (Maybe Text -> f (Maybe Text)) -> StopModel -> f StopModel
stopModel_clientToken = (StopModel -> Maybe Text)
-> (StopModel -> Maybe Text -> StopModel)
-> Lens StopModel StopModel (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopModel' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:StopModel' :: StopModel -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: StopModel
s@StopModel' {} Maybe Text
a -> StopModel
s {$sel:clientToken:StopModel' :: Maybe Text
clientToken = Maybe Text
a} :: StopModel)

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

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

instance Core.AWSRequest StopModel where
  type AWSResponse StopModel = StopModelResponse
  request :: StopModel -> Request StopModel
request = Service -> StopModel -> Request StopModel
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StopModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopModel)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StopModel))
-> Logger
-> Service
-> Proxy StopModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopModel)))
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 -> StopModelResponse
StopModelResponse'
            (Maybe ModelHostingStatus -> Int -> StopModelResponse)
-> Either String (Maybe ModelHostingStatus)
-> Either String (Int -> StopModelResponse)
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 -> StopModelResponse)
-> Either String Int -> Either String StopModelResponse
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 StopModel

instance Prelude.NFData StopModel

instance Core.ToHeaders StopModel where
  toHeaders :: StopModel -> ResponseHeaders
toHeaders StopModel' {Maybe Text
Text
modelVersion :: Text
projectName :: Text
clientToken :: Maybe Text
$sel:modelVersion:StopModel' :: StopModel -> Text
$sel:projectName:StopModel' :: StopModel -> Text
$sel:clientToken:StopModel' :: StopModel -> 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 StopModel where
  toJSON :: StopModel -> Value
toJSON = Value -> StopModel -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath StopModel where
  toPath :: StopModel -> ByteString
toPath StopModel' {Maybe Text
Text
modelVersion :: Text
projectName :: Text
clientToken :: Maybe Text
$sel:modelVersion:StopModel' :: StopModel -> Text
$sel:projectName:StopModel' :: StopModel -> Text
$sel:clientToken:StopModel' :: StopModel -> 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
"/stop"
      ]

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

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

-- |
-- Create a value of 'StopModelResponse' 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', 'stopModelResponse_status' - The status of the model.
--
-- 'httpStatus', 'stopModelResponse_httpStatus' - The response's http status code.
newStopModelResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopModelResponse
newStopModelResponse :: Int -> StopModelResponse
newStopModelResponse Int
pHttpStatus_ =
  StopModelResponse' :: Maybe ModelHostingStatus -> Int -> StopModelResponse
StopModelResponse'
    { $sel:status:StopModelResponse' :: Maybe ModelHostingStatus
status = Maybe ModelHostingStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopModelResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

instance Prelude.NFData StopModelResponse