{-# 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.FIS.StartExperiment
-- 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 running an experiment from the specified experiment template.
module Amazonka.FIS.StartExperiment
  ( -- * Creating a Request
    StartExperiment (..),
    newStartExperiment,

    -- * Request Lenses
    startExperiment_tags,
    startExperiment_clientToken,
    startExperiment_experimentTemplateId,

    -- * Destructuring the Response
    StartExperimentResponse (..),
    newStartExperimentResponse,

    -- * Response Lenses
    startExperimentResponse_experiment,
    startExperimentResponse_httpStatus,
  )
where

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

-- | /See:/ 'newStartExperiment' smart constructor.
data StartExperiment = StartExperiment'
  { -- | The tags to apply to the experiment.
    StartExperiment -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | Unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the request.
    StartExperiment -> Text
clientToken :: Prelude.Text,
    -- | The ID of the experiment template.
    StartExperiment -> Text
experimentTemplateId :: Prelude.Text
  }
  deriving (StartExperiment -> StartExperiment -> Bool
(StartExperiment -> StartExperiment -> Bool)
-> (StartExperiment -> StartExperiment -> Bool)
-> Eq StartExperiment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartExperiment -> StartExperiment -> Bool
$c/= :: StartExperiment -> StartExperiment -> Bool
== :: StartExperiment -> StartExperiment -> Bool
$c== :: StartExperiment -> StartExperiment -> Bool
Prelude.Eq, ReadPrec [StartExperiment]
ReadPrec StartExperiment
Int -> ReadS StartExperiment
ReadS [StartExperiment]
(Int -> ReadS StartExperiment)
-> ReadS [StartExperiment]
-> ReadPrec StartExperiment
-> ReadPrec [StartExperiment]
-> Read StartExperiment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartExperiment]
$creadListPrec :: ReadPrec [StartExperiment]
readPrec :: ReadPrec StartExperiment
$creadPrec :: ReadPrec StartExperiment
readList :: ReadS [StartExperiment]
$creadList :: ReadS [StartExperiment]
readsPrec :: Int -> ReadS StartExperiment
$creadsPrec :: Int -> ReadS StartExperiment
Prelude.Read, Int -> StartExperiment -> ShowS
[StartExperiment] -> ShowS
StartExperiment -> String
(Int -> StartExperiment -> ShowS)
-> (StartExperiment -> String)
-> ([StartExperiment] -> ShowS)
-> Show StartExperiment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartExperiment] -> ShowS
$cshowList :: [StartExperiment] -> ShowS
show :: StartExperiment -> String
$cshow :: StartExperiment -> String
showsPrec :: Int -> StartExperiment -> ShowS
$cshowsPrec :: Int -> StartExperiment -> ShowS
Prelude.Show, (forall x. StartExperiment -> Rep StartExperiment x)
-> (forall x. Rep StartExperiment x -> StartExperiment)
-> Generic StartExperiment
forall x. Rep StartExperiment x -> StartExperiment
forall x. StartExperiment -> Rep StartExperiment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartExperiment x -> StartExperiment
$cfrom :: forall x. StartExperiment -> Rep StartExperiment x
Prelude.Generic)

-- |
-- Create a value of 'StartExperiment' 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:
--
-- 'tags', 'startExperiment_tags' - The tags to apply to the experiment.
--
-- 'clientToken', 'startExperiment_clientToken' - Unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
--
-- 'experimentTemplateId', 'startExperiment_experimentTemplateId' - The ID of the experiment template.
newStartExperiment ::
  -- | 'clientToken'
  Prelude.Text ->
  -- | 'experimentTemplateId'
  Prelude.Text ->
  StartExperiment
newStartExperiment :: Text -> Text -> StartExperiment
newStartExperiment
  Text
pClientToken_
  Text
pExperimentTemplateId_ =
    StartExperiment' :: Maybe (HashMap Text Text) -> Text -> Text -> StartExperiment
StartExperiment'
      { $sel:tags:StartExperiment' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
        $sel:clientToken:StartExperiment' :: Text
clientToken = Text
pClientToken_,
        $sel:experimentTemplateId:StartExperiment' :: Text
experimentTemplateId = Text
pExperimentTemplateId_
      }

-- | The tags to apply to the experiment.
startExperiment_tags :: Lens.Lens' StartExperiment (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
startExperiment_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> StartExperiment -> f StartExperiment
startExperiment_tags = (StartExperiment -> Maybe (HashMap Text Text))
-> (StartExperiment
    -> Maybe (HashMap Text Text) -> StartExperiment)
-> Lens
     StartExperiment
     StartExperiment
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartExperiment' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:StartExperiment' :: StartExperiment -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: StartExperiment
s@StartExperiment' {} Maybe (HashMap Text Text)
a -> StartExperiment
s {$sel:tags:StartExperiment' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: StartExperiment) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> StartExperiment -> f StartExperiment)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> StartExperiment
-> f StartExperiment
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
startExperiment_clientToken :: Lens.Lens' StartExperiment Prelude.Text
startExperiment_clientToken :: (Text -> f Text) -> StartExperiment -> f StartExperiment
startExperiment_clientToken = (StartExperiment -> Text)
-> (StartExperiment -> Text -> StartExperiment)
-> Lens StartExperiment StartExperiment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartExperiment' {Text
clientToken :: Text
$sel:clientToken:StartExperiment' :: StartExperiment -> Text
clientToken} -> Text
clientToken) (\s :: StartExperiment
s@StartExperiment' {} Text
a -> StartExperiment
s {$sel:clientToken:StartExperiment' :: Text
clientToken = Text
a} :: StartExperiment)

-- | The ID of the experiment template.
startExperiment_experimentTemplateId :: Lens.Lens' StartExperiment Prelude.Text
startExperiment_experimentTemplateId :: (Text -> f Text) -> StartExperiment -> f StartExperiment
startExperiment_experimentTemplateId = (StartExperiment -> Text)
-> (StartExperiment -> Text -> StartExperiment)
-> Lens StartExperiment StartExperiment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartExperiment' {Text
experimentTemplateId :: Text
$sel:experimentTemplateId:StartExperiment' :: StartExperiment -> Text
experimentTemplateId} -> Text
experimentTemplateId) (\s :: StartExperiment
s@StartExperiment' {} Text
a -> StartExperiment
s {$sel:experimentTemplateId:StartExperiment' :: Text
experimentTemplateId = Text
a} :: StartExperiment)

instance Core.AWSRequest StartExperiment where
  type
    AWSResponse StartExperiment =
      StartExperimentResponse
  request :: StartExperiment -> Request StartExperiment
request = Service -> StartExperiment -> Request StartExperiment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartExperiment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartExperiment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartExperiment))
-> Logger
-> Service
-> Proxy StartExperiment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartExperiment)))
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 Experiment -> Int -> StartExperimentResponse
StartExperimentResponse'
            (Maybe Experiment -> Int -> StartExperimentResponse)
-> Either String (Maybe Experiment)
-> Either String (Int -> StartExperimentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Experiment)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"experiment")
            Either String (Int -> StartExperimentResponse)
-> Either String Int -> Either String StartExperimentResponse
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 StartExperiment

instance Prelude.NFData StartExperiment

instance Core.ToHeaders StartExperiment where
  toHeaders :: StartExperiment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartExperiment -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 StartExperiment where
  toJSON :: StartExperiment -> Value
toJSON StartExperiment' {Maybe (HashMap Text Text)
Text
experimentTemplateId :: Text
clientToken :: Text
tags :: Maybe (HashMap Text Text)
$sel:experimentTemplateId:StartExperiment' :: StartExperiment -> Text
$sel:clientToken:StartExperiment' :: StartExperiment -> Text
$sel:tags:StartExperiment' :: StartExperiment -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"clientToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientToken),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"experimentTemplateId"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
experimentTemplateId
              )
          ]
      )

instance Core.ToPath StartExperiment where
  toPath :: StartExperiment -> ByteString
toPath = ByteString -> StartExperiment -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/experiments"

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

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

-- |
-- Create a value of 'StartExperimentResponse' 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:
--
-- 'experiment', 'startExperimentResponse_experiment' - Information about the experiment.
--
-- 'httpStatus', 'startExperimentResponse_httpStatus' - The response's http status code.
newStartExperimentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartExperimentResponse
newStartExperimentResponse :: Int -> StartExperimentResponse
newStartExperimentResponse Int
pHttpStatus_ =
  StartExperimentResponse' :: Maybe Experiment -> Int -> StartExperimentResponse
StartExperimentResponse'
    { $sel:experiment:StartExperimentResponse' :: Maybe Experiment
experiment =
        Maybe Experiment
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartExperimentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the experiment.
startExperimentResponse_experiment :: Lens.Lens' StartExperimentResponse (Prelude.Maybe Experiment)
startExperimentResponse_experiment :: (Maybe Experiment -> f (Maybe Experiment))
-> StartExperimentResponse -> f StartExperimentResponse
startExperimentResponse_experiment = (StartExperimentResponse -> Maybe Experiment)
-> (StartExperimentResponse
    -> Maybe Experiment -> StartExperimentResponse)
-> Lens
     StartExperimentResponse
     StartExperimentResponse
     (Maybe Experiment)
     (Maybe Experiment)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartExperimentResponse' {Maybe Experiment
experiment :: Maybe Experiment
$sel:experiment:StartExperimentResponse' :: StartExperimentResponse -> Maybe Experiment
experiment} -> Maybe Experiment
experiment) (\s :: StartExperimentResponse
s@StartExperimentResponse' {} Maybe Experiment
a -> StartExperimentResponse
s {$sel:experiment:StartExperimentResponse' :: Maybe Experiment
experiment = Maybe Experiment
a} :: StartExperimentResponse)

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

instance Prelude.NFData StartExperimentResponse