{-# 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.DeviceFarm.StopRun
-- 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)
--
-- Initiates a stop request for the current test run. AWS Device Farm
-- immediately stops the run on devices where tests have not started. You
-- are not billed for these devices. On devices where tests have started
-- executing, setup suite and teardown suite tests run to completion on
-- those devices. You are billed for setup, teardown, and any tests that
-- were in progress or already completed.
module Amazonka.DeviceFarm.StopRun
  ( -- * Creating a Request
    StopRun (..),
    newStopRun,

    -- * Request Lenses
    stopRun_arn,

    -- * Destructuring the Response
    StopRunResponse (..),
    newStopRunResponse,

    -- * Response Lenses
    stopRunResponse_run,
    stopRunResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DeviceFarm.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

-- | Represents the request to stop a specific run.
--
-- /See:/ 'newStopRun' smart constructor.
data StopRun = StopRun'
  { -- | Represents the Amazon Resource Name (ARN) of the Device Farm run to
    -- stop.
    StopRun -> Text
arn :: Prelude.Text
  }
  deriving (StopRun -> StopRun -> Bool
(StopRun -> StopRun -> Bool)
-> (StopRun -> StopRun -> Bool) -> Eq StopRun
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopRun -> StopRun -> Bool
$c/= :: StopRun -> StopRun -> Bool
== :: StopRun -> StopRun -> Bool
$c== :: StopRun -> StopRun -> Bool
Prelude.Eq, ReadPrec [StopRun]
ReadPrec StopRun
Int -> ReadS StopRun
ReadS [StopRun]
(Int -> ReadS StopRun)
-> ReadS [StopRun]
-> ReadPrec StopRun
-> ReadPrec [StopRun]
-> Read StopRun
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopRun]
$creadListPrec :: ReadPrec [StopRun]
readPrec :: ReadPrec StopRun
$creadPrec :: ReadPrec StopRun
readList :: ReadS [StopRun]
$creadList :: ReadS [StopRun]
readsPrec :: Int -> ReadS StopRun
$creadsPrec :: Int -> ReadS StopRun
Prelude.Read, Int -> StopRun -> ShowS
[StopRun] -> ShowS
StopRun -> String
(Int -> StopRun -> ShowS)
-> (StopRun -> String) -> ([StopRun] -> ShowS) -> Show StopRun
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopRun] -> ShowS
$cshowList :: [StopRun] -> ShowS
show :: StopRun -> String
$cshow :: StopRun -> String
showsPrec :: Int -> StopRun -> ShowS
$cshowsPrec :: Int -> StopRun -> ShowS
Prelude.Show, (forall x. StopRun -> Rep StopRun x)
-> (forall x. Rep StopRun x -> StopRun) -> Generic StopRun
forall x. Rep StopRun x -> StopRun
forall x. StopRun -> Rep StopRun x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopRun x -> StopRun
$cfrom :: forall x. StopRun -> Rep StopRun x
Prelude.Generic)

-- |
-- Create a value of 'StopRun' 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:
--
-- 'arn', 'stopRun_arn' - Represents the Amazon Resource Name (ARN) of the Device Farm run to
-- stop.
newStopRun ::
  -- | 'arn'
  Prelude.Text ->
  StopRun
newStopRun :: Text -> StopRun
newStopRun Text
pArn_ = StopRun' :: Text -> StopRun
StopRun' {$sel:arn:StopRun' :: Text
arn = Text
pArn_}

-- | Represents the Amazon Resource Name (ARN) of the Device Farm run to
-- stop.
stopRun_arn :: Lens.Lens' StopRun Prelude.Text
stopRun_arn :: (Text -> f Text) -> StopRun -> f StopRun
stopRun_arn = (StopRun -> Text)
-> (StopRun -> Text -> StopRun) -> Lens StopRun StopRun Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopRun' {Text
arn :: Text
$sel:arn:StopRun' :: StopRun -> Text
arn} -> Text
arn) (\s :: StopRun
s@StopRun' {} Text
a -> StopRun
s {$sel:arn:StopRun' :: Text
arn = Text
a} :: StopRun)

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

instance Prelude.NFData StopRun

instance Core.ToHeaders StopRun where
  toHeaders :: StopRun -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StopRun -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"DeviceFarm_20150623.StopRun" ::
                          Prelude.ByteString
                      ),
            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 StopRun where
  toJSON :: StopRun -> Value
toJSON StopRun' {Text
arn :: Text
$sel:arn:StopRun' :: StopRun -> 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
"arn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
arn)]
      )

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

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

-- | Represents the results of your stop run attempt.
--
-- /See:/ 'newStopRunResponse' smart constructor.
data StopRunResponse = StopRunResponse'
  { -- | The run that was stopped.
    StopRunResponse -> Maybe Run
run :: Prelude.Maybe Run,
    -- | The response's http status code.
    StopRunResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopRunResponse -> StopRunResponse -> Bool
(StopRunResponse -> StopRunResponse -> Bool)
-> (StopRunResponse -> StopRunResponse -> Bool)
-> Eq StopRunResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopRunResponse -> StopRunResponse -> Bool
$c/= :: StopRunResponse -> StopRunResponse -> Bool
== :: StopRunResponse -> StopRunResponse -> Bool
$c== :: StopRunResponse -> StopRunResponse -> Bool
Prelude.Eq, ReadPrec [StopRunResponse]
ReadPrec StopRunResponse
Int -> ReadS StopRunResponse
ReadS [StopRunResponse]
(Int -> ReadS StopRunResponse)
-> ReadS [StopRunResponse]
-> ReadPrec StopRunResponse
-> ReadPrec [StopRunResponse]
-> Read StopRunResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopRunResponse]
$creadListPrec :: ReadPrec [StopRunResponse]
readPrec :: ReadPrec StopRunResponse
$creadPrec :: ReadPrec StopRunResponse
readList :: ReadS [StopRunResponse]
$creadList :: ReadS [StopRunResponse]
readsPrec :: Int -> ReadS StopRunResponse
$creadsPrec :: Int -> ReadS StopRunResponse
Prelude.Read, Int -> StopRunResponse -> ShowS
[StopRunResponse] -> ShowS
StopRunResponse -> String
(Int -> StopRunResponse -> ShowS)
-> (StopRunResponse -> String)
-> ([StopRunResponse] -> ShowS)
-> Show StopRunResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopRunResponse] -> ShowS
$cshowList :: [StopRunResponse] -> ShowS
show :: StopRunResponse -> String
$cshow :: StopRunResponse -> String
showsPrec :: Int -> StopRunResponse -> ShowS
$cshowsPrec :: Int -> StopRunResponse -> ShowS
Prelude.Show, (forall x. StopRunResponse -> Rep StopRunResponse x)
-> (forall x. Rep StopRunResponse x -> StopRunResponse)
-> Generic StopRunResponse
forall x. Rep StopRunResponse x -> StopRunResponse
forall x. StopRunResponse -> Rep StopRunResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopRunResponse x -> StopRunResponse
$cfrom :: forall x. StopRunResponse -> Rep StopRunResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopRunResponse' 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:
--
-- 'run', 'stopRunResponse_run' - The run that was stopped.
--
-- 'httpStatus', 'stopRunResponse_httpStatus' - The response's http status code.
newStopRunResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopRunResponse
newStopRunResponse :: Int -> StopRunResponse
newStopRunResponse Int
pHttpStatus_ =
  StopRunResponse' :: Maybe Run -> Int -> StopRunResponse
StopRunResponse'
    { $sel:run:StopRunResponse' :: Maybe Run
run = Maybe Run
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopRunResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The run that was stopped.
stopRunResponse_run :: Lens.Lens' StopRunResponse (Prelude.Maybe Run)
stopRunResponse_run :: (Maybe Run -> f (Maybe Run))
-> StopRunResponse -> f StopRunResponse
stopRunResponse_run = (StopRunResponse -> Maybe Run)
-> (StopRunResponse -> Maybe Run -> StopRunResponse)
-> Lens StopRunResponse StopRunResponse (Maybe Run) (Maybe Run)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopRunResponse' {Maybe Run
run :: Maybe Run
$sel:run:StopRunResponse' :: StopRunResponse -> Maybe Run
run} -> Maybe Run
run) (\s :: StopRunResponse
s@StopRunResponse' {} Maybe Run
a -> StopRunResponse
s {$sel:run:StopRunResponse' :: Maybe Run
run = Maybe Run
a} :: StopRunResponse)

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

instance Prelude.NFData StopRunResponse