{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DeviceFarm.Types
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
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]
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
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. 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' {$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 :: Lens' StopRun Text
stopRun_arn = 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 :: (Service -> Service) -> StopRun -> Request StopRun
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 StopRun
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopRun)))
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 Run -> Int -> StopRunResponse
StopRunResponse'
            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
"run")
            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 StopRun where
  hashWithSalt :: Int -> StopRun -> Int
hashWithSalt Int
_salt StopRun' {Text
arn :: Text
$sel:arn:StopRun' :: StopRun -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn

instance Prelude.NFData StopRun where
  rnf :: StopRun -> ()
rnf StopRun' {Text
arn :: Text
$sel:arn:StopRun' :: StopRun -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
arn

instance Data.ToHeaders StopRun where
  toHeaders :: StopRun -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"DeviceFarm_20150623.StopRun" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON StopRun where
  toJSON :: StopRun -> Value
toJSON StopRun' {Text
arn :: Text
$sel:arn:StopRun' :: StopRun -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"arn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
arn)]
      )

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

instance Data.ToQuery StopRun where
  toQuery :: StopRun -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:run:StopRunResponse' :: Maybe Run
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 :: Lens' StopRunResponse (Maybe Run)
stopRunResponse_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 :: Lens' StopRunResponse Int
stopRunResponse_httpStatus = 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 where
  rnf :: StopRunResponse -> ()
rnf StopRunResponse' {Int
Maybe Run
httpStatus :: Int
run :: Maybe Run
$sel:httpStatus:StopRunResponse' :: StopRunResponse -> Int
$sel:run:StopRunResponse' :: StopRunResponse -> Maybe Run
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Run
run
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus