{-# 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.StopJob
-- 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 job. AWS Device Farm
-- immediately stops the job on the device where tests have not started.
-- You are not billed for this device. On the device where tests have
-- started, setup suite and teardown suite tests run to completion on the
-- device. You are billed for setup, teardown, and any tests that were in
-- progress or already completed.
module Amazonka.DeviceFarm.StopJob
  ( -- * Creating a Request
    StopJob (..),
    newStopJob,

    -- * Request Lenses
    stopJob_arn,

    -- * Destructuring the Response
    StopJobResponse (..),
    newStopJobResponse,

    -- * Response Lenses
    stopJobResponse_job,
    stopJobResponse_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

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

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

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

instance Core.AWSRequest StopJob where
  type AWSResponse StopJob = StopJobResponse
  request :: (Service -> Service) -> StopJob -> Request StopJob
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 StopJob
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopJob)))
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 Job -> Int -> StopJobResponse
StopJobResponse'
            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
"job")
            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 StopJob where
  hashWithSalt :: Int -> StopJob -> Int
hashWithSalt Int
_salt StopJob' {Text
arn :: Text
$sel:arn:StopJob' :: StopJob -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn

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

instance Data.ToHeaders StopJob where
  toHeaders :: StopJob -> 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.StopJob" ::
                          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 StopJob where
  toJSON :: StopJob -> Value
toJSON StopJob' {Text
arn :: Text
$sel:arn:StopJob' :: StopJob -> 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 StopJob where
  toPath :: StopJob -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'StopJobResponse' 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:
--
-- 'job', 'stopJobResponse_job' - The job that was stopped.
--
-- 'httpStatus', 'stopJobResponse_httpStatus' - The response's http status code.
newStopJobResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopJobResponse
newStopJobResponse :: Int -> StopJobResponse
newStopJobResponse Int
pHttpStatus_ =
  StopJobResponse'
    { $sel:job:StopJobResponse' :: Maybe Job
job = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopJobResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The job that was stopped.
stopJobResponse_job :: Lens.Lens' StopJobResponse (Prelude.Maybe Job)
stopJobResponse_job :: Lens' StopJobResponse (Maybe Job)
stopJobResponse_job = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopJobResponse' {Maybe Job
job :: Maybe Job
$sel:job:StopJobResponse' :: StopJobResponse -> Maybe Job
job} -> Maybe Job
job) (\s :: StopJobResponse
s@StopJobResponse' {} Maybe Job
a -> StopJobResponse
s {$sel:job:StopJobResponse' :: Maybe Job
job = Maybe Job
a} :: StopJobResponse)

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

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