{-# 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.Evidently.StopExperiment
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Stops an experiment that is currently running. If you stop an
-- experiment, you can\'t resume it or restart it.
module Amazonka.Evidently.StopExperiment
  ( -- * Creating a Request
    StopExperiment (..),
    newStopExperiment,

    -- * Request Lenses
    stopExperiment_desiredState,
    stopExperiment_reason,
    stopExperiment_experiment,
    stopExperiment_project,

    -- * Destructuring the Response
    StopExperimentResponse (..),
    newStopExperimentResponse,

    -- * Response Lenses
    stopExperimentResponse_endedTime,
    stopExperimentResponse_httpStatus,
  )
where

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

-- | /See:/ 'newStopExperiment' smart constructor.
data StopExperiment = StopExperiment'
  { -- | Specify whether the experiment is to be considered @COMPLETED@ or
    -- @CANCELLED@ after it stops.
    StopExperiment -> Maybe ExperimentStopDesiredState
desiredState :: Prelude.Maybe ExperimentStopDesiredState,
    -- | A string that describes why you are stopping the experiment.
    StopExperiment -> Maybe Text
reason :: Prelude.Maybe Prelude.Text,
    -- | The name of the experiment to stop.
    StopExperiment -> Text
experiment :: Prelude.Text,
    -- | The name or ARN of the project that contains the experiment to stop.
    StopExperiment -> Text
project :: Prelude.Text
  }
  deriving (StopExperiment -> StopExperiment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopExperiment -> StopExperiment -> Bool
$c/= :: StopExperiment -> StopExperiment -> Bool
== :: StopExperiment -> StopExperiment -> Bool
$c== :: StopExperiment -> StopExperiment -> Bool
Prelude.Eq, ReadPrec [StopExperiment]
ReadPrec StopExperiment
Int -> ReadS StopExperiment
ReadS [StopExperiment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopExperiment]
$creadListPrec :: ReadPrec [StopExperiment]
readPrec :: ReadPrec StopExperiment
$creadPrec :: ReadPrec StopExperiment
readList :: ReadS [StopExperiment]
$creadList :: ReadS [StopExperiment]
readsPrec :: Int -> ReadS StopExperiment
$creadsPrec :: Int -> ReadS StopExperiment
Prelude.Read, Int -> StopExperiment -> ShowS
[StopExperiment] -> ShowS
StopExperiment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopExperiment] -> ShowS
$cshowList :: [StopExperiment] -> ShowS
show :: StopExperiment -> String
$cshow :: StopExperiment -> String
showsPrec :: Int -> StopExperiment -> ShowS
$cshowsPrec :: Int -> StopExperiment -> ShowS
Prelude.Show, forall x. Rep StopExperiment x -> StopExperiment
forall x. StopExperiment -> Rep StopExperiment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopExperiment x -> StopExperiment
$cfrom :: forall x. StopExperiment -> Rep StopExperiment x
Prelude.Generic)

-- |
-- Create a value of 'StopExperiment' 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:
--
-- 'desiredState', 'stopExperiment_desiredState' - Specify whether the experiment is to be considered @COMPLETED@ or
-- @CANCELLED@ after it stops.
--
-- 'reason', 'stopExperiment_reason' - A string that describes why you are stopping the experiment.
--
-- 'experiment', 'stopExperiment_experiment' - The name of the experiment to stop.
--
-- 'project', 'stopExperiment_project' - The name or ARN of the project that contains the experiment to stop.
newStopExperiment ::
  -- | 'experiment'
  Prelude.Text ->
  -- | 'project'
  Prelude.Text ->
  StopExperiment
newStopExperiment :: Text -> Text -> StopExperiment
newStopExperiment Text
pExperiment_ Text
pProject_ =
  StopExperiment'
    { $sel:desiredState:StopExperiment' :: Maybe ExperimentStopDesiredState
desiredState = forall a. Maybe a
Prelude.Nothing,
      $sel:reason:StopExperiment' :: Maybe Text
reason = forall a. Maybe a
Prelude.Nothing,
      $sel:experiment:StopExperiment' :: Text
experiment = Text
pExperiment_,
      $sel:project:StopExperiment' :: Text
project = Text
pProject_
    }

-- | Specify whether the experiment is to be considered @COMPLETED@ or
-- @CANCELLED@ after it stops.
stopExperiment_desiredState :: Lens.Lens' StopExperiment (Prelude.Maybe ExperimentStopDesiredState)
stopExperiment_desiredState :: Lens' StopExperiment (Maybe ExperimentStopDesiredState)
stopExperiment_desiredState = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExperiment' {Maybe ExperimentStopDesiredState
desiredState :: Maybe ExperimentStopDesiredState
$sel:desiredState:StopExperiment' :: StopExperiment -> Maybe ExperimentStopDesiredState
desiredState} -> Maybe ExperimentStopDesiredState
desiredState) (\s :: StopExperiment
s@StopExperiment' {} Maybe ExperimentStopDesiredState
a -> StopExperiment
s {$sel:desiredState:StopExperiment' :: Maybe ExperimentStopDesiredState
desiredState = Maybe ExperimentStopDesiredState
a} :: StopExperiment)

-- | A string that describes why you are stopping the experiment.
stopExperiment_reason :: Lens.Lens' StopExperiment (Prelude.Maybe Prelude.Text)
stopExperiment_reason :: Lens' StopExperiment (Maybe Text)
stopExperiment_reason = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExperiment' {Maybe Text
reason :: Maybe Text
$sel:reason:StopExperiment' :: StopExperiment -> Maybe Text
reason} -> Maybe Text
reason) (\s :: StopExperiment
s@StopExperiment' {} Maybe Text
a -> StopExperiment
s {$sel:reason:StopExperiment' :: Maybe Text
reason = Maybe Text
a} :: StopExperiment)

-- | The name of the experiment to stop.
stopExperiment_experiment :: Lens.Lens' StopExperiment Prelude.Text
stopExperiment_experiment :: Lens' StopExperiment Text
stopExperiment_experiment = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExperiment' {Text
experiment :: Text
$sel:experiment:StopExperiment' :: StopExperiment -> Text
experiment} -> Text
experiment) (\s :: StopExperiment
s@StopExperiment' {} Text
a -> StopExperiment
s {$sel:experiment:StopExperiment' :: Text
experiment = Text
a} :: StopExperiment)

-- | The name or ARN of the project that contains the experiment to stop.
stopExperiment_project :: Lens.Lens' StopExperiment Prelude.Text
stopExperiment_project :: Lens' StopExperiment Text
stopExperiment_project = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExperiment' {Text
project :: Text
$sel:project:StopExperiment' :: StopExperiment -> Text
project} -> Text
project) (\s :: StopExperiment
s@StopExperiment' {} Text
a -> StopExperiment
s {$sel:project:StopExperiment' :: Text
project = Text
a} :: StopExperiment)

instance Core.AWSRequest StopExperiment where
  type
    AWSResponse StopExperiment =
      StopExperimentResponse
  request :: (Service -> Service) -> StopExperiment -> Request StopExperiment
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 StopExperiment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopExperiment)))
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 POSIX -> Int -> StopExperimentResponse
StopExperimentResponse'
            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
"endedTime")
            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 StopExperiment where
  hashWithSalt :: Int -> StopExperiment -> Int
hashWithSalt Int
_salt StopExperiment' {Maybe Text
Maybe ExperimentStopDesiredState
Text
project :: Text
experiment :: Text
reason :: Maybe Text
desiredState :: Maybe ExperimentStopDesiredState
$sel:project:StopExperiment' :: StopExperiment -> Text
$sel:experiment:StopExperiment' :: StopExperiment -> Text
$sel:reason:StopExperiment' :: StopExperiment -> Maybe Text
$sel:desiredState:StopExperiment' :: StopExperiment -> Maybe ExperimentStopDesiredState
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ExperimentStopDesiredState
desiredState
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
reason
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
experiment
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
project

instance Prelude.NFData StopExperiment where
  rnf :: StopExperiment -> ()
rnf StopExperiment' {Maybe Text
Maybe ExperimentStopDesiredState
Text
project :: Text
experiment :: Text
reason :: Maybe Text
desiredState :: Maybe ExperimentStopDesiredState
$sel:project:StopExperiment' :: StopExperiment -> Text
$sel:experiment:StopExperiment' :: StopExperiment -> Text
$sel:reason:StopExperiment' :: StopExperiment -> Maybe Text
$sel:desiredState:StopExperiment' :: StopExperiment -> Maybe ExperimentStopDesiredState
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ExperimentStopDesiredState
desiredState
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
reason
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
experiment
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
project

instance Data.ToHeaders StopExperiment where
  toHeaders :: StopExperiment -> 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.ToJSON StopExperiment where
  toJSON :: StopExperiment -> Value
toJSON StopExperiment' {Maybe Text
Maybe ExperimentStopDesiredState
Text
project :: Text
experiment :: Text
reason :: Maybe Text
desiredState :: Maybe ExperimentStopDesiredState
$sel:project:StopExperiment' :: StopExperiment -> Text
$sel:experiment:StopExperiment' :: StopExperiment -> Text
$sel:reason:StopExperiment' :: StopExperiment -> Maybe Text
$sel:desiredState:StopExperiment' :: StopExperiment -> Maybe ExperimentStopDesiredState
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"desiredState" 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 ExperimentStopDesiredState
desiredState,
            (Key
"reason" 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
reason
          ]
      )

instance Data.ToPath StopExperiment where
  toPath :: StopExperiment -> ByteString
toPath StopExperiment' {Maybe Text
Maybe ExperimentStopDesiredState
Text
project :: Text
experiment :: Text
reason :: Maybe Text
desiredState :: Maybe ExperimentStopDesiredState
$sel:project:StopExperiment' :: StopExperiment -> Text
$sel:experiment:StopExperiment' :: StopExperiment -> Text
$sel:reason:StopExperiment' :: StopExperiment -> Maybe Text
$sel:desiredState:StopExperiment' :: StopExperiment -> Maybe ExperimentStopDesiredState
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/projects/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
project,
        ByteString
"/experiments/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
experiment,
        ByteString
"/cancel"
      ]

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

-- | /See:/ 'newStopExperimentResponse' smart constructor.
data StopExperimentResponse = StopExperimentResponse'
  { -- | The date and time that the experiment stopped.
    StopExperimentResponse -> Maybe POSIX
endedTime :: Prelude.Maybe Data.POSIX,
    -- | The response's http status code.
    StopExperimentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopExperimentResponse -> StopExperimentResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopExperimentResponse -> StopExperimentResponse -> Bool
$c/= :: StopExperimentResponse -> StopExperimentResponse -> Bool
== :: StopExperimentResponse -> StopExperimentResponse -> Bool
$c== :: StopExperimentResponse -> StopExperimentResponse -> Bool
Prelude.Eq, ReadPrec [StopExperimentResponse]
ReadPrec StopExperimentResponse
Int -> ReadS StopExperimentResponse
ReadS [StopExperimentResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopExperimentResponse]
$creadListPrec :: ReadPrec [StopExperimentResponse]
readPrec :: ReadPrec StopExperimentResponse
$creadPrec :: ReadPrec StopExperimentResponse
readList :: ReadS [StopExperimentResponse]
$creadList :: ReadS [StopExperimentResponse]
readsPrec :: Int -> ReadS StopExperimentResponse
$creadsPrec :: Int -> ReadS StopExperimentResponse
Prelude.Read, Int -> StopExperimentResponse -> ShowS
[StopExperimentResponse] -> ShowS
StopExperimentResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopExperimentResponse] -> ShowS
$cshowList :: [StopExperimentResponse] -> ShowS
show :: StopExperimentResponse -> String
$cshow :: StopExperimentResponse -> String
showsPrec :: Int -> StopExperimentResponse -> ShowS
$cshowsPrec :: Int -> StopExperimentResponse -> ShowS
Prelude.Show, forall x. Rep StopExperimentResponse x -> StopExperimentResponse
forall x. StopExperimentResponse -> Rep StopExperimentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopExperimentResponse x -> StopExperimentResponse
$cfrom :: forall x. StopExperimentResponse -> Rep StopExperimentResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopExperimentResponse' 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:
--
-- 'endedTime', 'stopExperimentResponse_endedTime' - The date and time that the experiment stopped.
--
-- 'httpStatus', 'stopExperimentResponse_httpStatus' - The response's http status code.
newStopExperimentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopExperimentResponse
newStopExperimentResponse :: Int -> StopExperimentResponse
newStopExperimentResponse Int
pHttpStatus_ =
  StopExperimentResponse'
    { $sel:endedTime:StopExperimentResponse' :: Maybe POSIX
endedTime =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopExperimentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The date and time that the experiment stopped.
stopExperimentResponse_endedTime :: Lens.Lens' StopExperimentResponse (Prelude.Maybe Prelude.UTCTime)
stopExperimentResponse_endedTime :: Lens' StopExperimentResponse (Maybe UTCTime)
stopExperimentResponse_endedTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExperimentResponse' {Maybe POSIX
endedTime :: Maybe POSIX
$sel:endedTime:StopExperimentResponse' :: StopExperimentResponse -> Maybe POSIX
endedTime} -> Maybe POSIX
endedTime) (\s :: StopExperimentResponse
s@StopExperimentResponse' {} Maybe POSIX
a -> StopExperimentResponse
s {$sel:endedTime:StopExperimentResponse' :: Maybe POSIX
endedTime = Maybe POSIX
a} :: StopExperimentResponse) 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 (a :: Format). Iso' (Time a) UTCTime
Data._Time

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

instance Prelude.NFData StopExperimentResponse where
  rnf :: StopExperimentResponse -> ()
rnf StopExperimentResponse' {Int
Maybe POSIX
httpStatus :: Int
endedTime :: Maybe POSIX
$sel:httpStatus:StopExperimentResponse' :: StopExperimentResponse -> Int
$sel:endedTime:StopExperimentResponse' :: StopExperimentResponse -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
endedTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus