{-# 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.RenewOffering
-- 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)
--
-- Explicitly sets the quantity of devices to renew for an offering,
-- starting from the @effectiveDate@ of the next period. The API returns a
-- @NotEligible@ error if the user is not permitted to invoke the
-- operation. If you must be able to invoke this operation, contact
-- <mailto:aws-devicefarm-support@amazon.com aws-devicefarm-support\@amazon.com>.
module Amazonka.DeviceFarm.RenewOffering
  ( -- * Creating a Request
    RenewOffering (..),
    newRenewOffering,

    -- * Request Lenses
    renewOffering_offeringId,
    renewOffering_quantity,

    -- * Destructuring the Response
    RenewOfferingResponse (..),
    newRenewOfferingResponse,

    -- * Response Lenses
    renewOfferingResponse_offeringTransaction,
    renewOfferingResponse_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

-- | A request that represents an offering renewal.
--
-- /See:/ 'newRenewOffering' smart constructor.
data RenewOffering = RenewOffering'
  { -- | The ID of a request to renew an offering.
    RenewOffering -> Text
offeringId :: Prelude.Text,
    -- | The quantity requested in an offering renewal.
    RenewOffering -> Int
quantity :: Prelude.Int
  }
  deriving (RenewOffering -> RenewOffering -> Bool
(RenewOffering -> RenewOffering -> Bool)
-> (RenewOffering -> RenewOffering -> Bool) -> Eq RenewOffering
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RenewOffering -> RenewOffering -> Bool
$c/= :: RenewOffering -> RenewOffering -> Bool
== :: RenewOffering -> RenewOffering -> Bool
$c== :: RenewOffering -> RenewOffering -> Bool
Prelude.Eq, ReadPrec [RenewOffering]
ReadPrec RenewOffering
Int -> ReadS RenewOffering
ReadS [RenewOffering]
(Int -> ReadS RenewOffering)
-> ReadS [RenewOffering]
-> ReadPrec RenewOffering
-> ReadPrec [RenewOffering]
-> Read RenewOffering
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RenewOffering]
$creadListPrec :: ReadPrec [RenewOffering]
readPrec :: ReadPrec RenewOffering
$creadPrec :: ReadPrec RenewOffering
readList :: ReadS [RenewOffering]
$creadList :: ReadS [RenewOffering]
readsPrec :: Int -> ReadS RenewOffering
$creadsPrec :: Int -> ReadS RenewOffering
Prelude.Read, Int -> RenewOffering -> ShowS
[RenewOffering] -> ShowS
RenewOffering -> String
(Int -> RenewOffering -> ShowS)
-> (RenewOffering -> String)
-> ([RenewOffering] -> ShowS)
-> Show RenewOffering
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RenewOffering] -> ShowS
$cshowList :: [RenewOffering] -> ShowS
show :: RenewOffering -> String
$cshow :: RenewOffering -> String
showsPrec :: Int -> RenewOffering -> ShowS
$cshowsPrec :: Int -> RenewOffering -> ShowS
Prelude.Show, (forall x. RenewOffering -> Rep RenewOffering x)
-> (forall x. Rep RenewOffering x -> RenewOffering)
-> Generic RenewOffering
forall x. Rep RenewOffering x -> RenewOffering
forall x. RenewOffering -> Rep RenewOffering x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RenewOffering x -> RenewOffering
$cfrom :: forall x. RenewOffering -> Rep RenewOffering x
Prelude.Generic)

-- |
-- Create a value of 'RenewOffering' 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:
--
-- 'offeringId', 'renewOffering_offeringId' - The ID of a request to renew an offering.
--
-- 'quantity', 'renewOffering_quantity' - The quantity requested in an offering renewal.
newRenewOffering ::
  -- | 'offeringId'
  Prelude.Text ->
  -- | 'quantity'
  Prelude.Int ->
  RenewOffering
newRenewOffering :: Text -> Int -> RenewOffering
newRenewOffering Text
pOfferingId_ Int
pQuantity_ =
  RenewOffering' :: Text -> Int -> RenewOffering
RenewOffering'
    { $sel:offeringId:RenewOffering' :: Text
offeringId = Text
pOfferingId_,
      $sel:quantity:RenewOffering' :: Int
quantity = Int
pQuantity_
    }

-- | The ID of a request to renew an offering.
renewOffering_offeringId :: Lens.Lens' RenewOffering Prelude.Text
renewOffering_offeringId :: (Text -> f Text) -> RenewOffering -> f RenewOffering
renewOffering_offeringId = (RenewOffering -> Text)
-> (RenewOffering -> Text -> RenewOffering)
-> Lens RenewOffering RenewOffering Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RenewOffering' {Text
offeringId :: Text
$sel:offeringId:RenewOffering' :: RenewOffering -> Text
offeringId} -> Text
offeringId) (\s :: RenewOffering
s@RenewOffering' {} Text
a -> RenewOffering
s {$sel:offeringId:RenewOffering' :: Text
offeringId = Text
a} :: RenewOffering)

-- | The quantity requested in an offering renewal.
renewOffering_quantity :: Lens.Lens' RenewOffering Prelude.Int
renewOffering_quantity :: (Int -> f Int) -> RenewOffering -> f RenewOffering
renewOffering_quantity = (RenewOffering -> Int)
-> (RenewOffering -> Int -> RenewOffering)
-> Lens RenewOffering RenewOffering Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RenewOffering' {Int
quantity :: Int
$sel:quantity:RenewOffering' :: RenewOffering -> Int
quantity} -> Int
quantity) (\s :: RenewOffering
s@RenewOffering' {} Int
a -> RenewOffering
s {$sel:quantity:RenewOffering' :: Int
quantity = Int
a} :: RenewOffering)

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

instance Prelude.NFData RenewOffering

instance Core.ToHeaders RenewOffering where
  toHeaders :: RenewOffering -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RenewOffering -> 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.RenewOffering" ::
                          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 RenewOffering where
  toJSON :: RenewOffering -> Value
toJSON RenewOffering' {Int
Text
quantity :: Int
offeringId :: Text
$sel:quantity:RenewOffering' :: RenewOffering -> Int
$sel:offeringId:RenewOffering' :: RenewOffering -> 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
"offeringId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
offeringId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"quantity" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
quantity)
          ]
      )

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

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

-- | The result of a renewal offering.
--
-- /See:/ 'newRenewOfferingResponse' smart constructor.
data RenewOfferingResponse = RenewOfferingResponse'
  { -- | Represents the status of the offering transaction for the renewal.
    RenewOfferingResponse -> Maybe OfferingTransaction
offeringTransaction :: Prelude.Maybe OfferingTransaction,
    -- | The response's http status code.
    RenewOfferingResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RenewOfferingResponse -> RenewOfferingResponse -> Bool
(RenewOfferingResponse -> RenewOfferingResponse -> Bool)
-> (RenewOfferingResponse -> RenewOfferingResponse -> Bool)
-> Eq RenewOfferingResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RenewOfferingResponse -> RenewOfferingResponse -> Bool
$c/= :: RenewOfferingResponse -> RenewOfferingResponse -> Bool
== :: RenewOfferingResponse -> RenewOfferingResponse -> Bool
$c== :: RenewOfferingResponse -> RenewOfferingResponse -> Bool
Prelude.Eq, ReadPrec [RenewOfferingResponse]
ReadPrec RenewOfferingResponse
Int -> ReadS RenewOfferingResponse
ReadS [RenewOfferingResponse]
(Int -> ReadS RenewOfferingResponse)
-> ReadS [RenewOfferingResponse]
-> ReadPrec RenewOfferingResponse
-> ReadPrec [RenewOfferingResponse]
-> Read RenewOfferingResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RenewOfferingResponse]
$creadListPrec :: ReadPrec [RenewOfferingResponse]
readPrec :: ReadPrec RenewOfferingResponse
$creadPrec :: ReadPrec RenewOfferingResponse
readList :: ReadS [RenewOfferingResponse]
$creadList :: ReadS [RenewOfferingResponse]
readsPrec :: Int -> ReadS RenewOfferingResponse
$creadsPrec :: Int -> ReadS RenewOfferingResponse
Prelude.Read, Int -> RenewOfferingResponse -> ShowS
[RenewOfferingResponse] -> ShowS
RenewOfferingResponse -> String
(Int -> RenewOfferingResponse -> ShowS)
-> (RenewOfferingResponse -> String)
-> ([RenewOfferingResponse] -> ShowS)
-> Show RenewOfferingResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RenewOfferingResponse] -> ShowS
$cshowList :: [RenewOfferingResponse] -> ShowS
show :: RenewOfferingResponse -> String
$cshow :: RenewOfferingResponse -> String
showsPrec :: Int -> RenewOfferingResponse -> ShowS
$cshowsPrec :: Int -> RenewOfferingResponse -> ShowS
Prelude.Show, (forall x. RenewOfferingResponse -> Rep RenewOfferingResponse x)
-> (forall x. Rep RenewOfferingResponse x -> RenewOfferingResponse)
-> Generic RenewOfferingResponse
forall x. Rep RenewOfferingResponse x -> RenewOfferingResponse
forall x. RenewOfferingResponse -> Rep RenewOfferingResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RenewOfferingResponse x -> RenewOfferingResponse
$cfrom :: forall x. RenewOfferingResponse -> Rep RenewOfferingResponse x
Prelude.Generic)

-- |
-- Create a value of 'RenewOfferingResponse' 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:
--
-- 'offeringTransaction', 'renewOfferingResponse_offeringTransaction' - Represents the status of the offering transaction for the renewal.
--
-- 'httpStatus', 'renewOfferingResponse_httpStatus' - The response's http status code.
newRenewOfferingResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RenewOfferingResponse
newRenewOfferingResponse :: Int -> RenewOfferingResponse
newRenewOfferingResponse Int
pHttpStatus_ =
  RenewOfferingResponse' :: Maybe OfferingTransaction -> Int -> RenewOfferingResponse
RenewOfferingResponse'
    { $sel:offeringTransaction:RenewOfferingResponse' :: Maybe OfferingTransaction
offeringTransaction =
        Maybe OfferingTransaction
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RenewOfferingResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Represents the status of the offering transaction for the renewal.
renewOfferingResponse_offeringTransaction :: Lens.Lens' RenewOfferingResponse (Prelude.Maybe OfferingTransaction)
renewOfferingResponse_offeringTransaction :: (Maybe OfferingTransaction -> f (Maybe OfferingTransaction))
-> RenewOfferingResponse -> f RenewOfferingResponse
renewOfferingResponse_offeringTransaction = (RenewOfferingResponse -> Maybe OfferingTransaction)
-> (RenewOfferingResponse
    -> Maybe OfferingTransaction -> RenewOfferingResponse)
-> Lens
     RenewOfferingResponse
     RenewOfferingResponse
     (Maybe OfferingTransaction)
     (Maybe OfferingTransaction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RenewOfferingResponse' {Maybe OfferingTransaction
offeringTransaction :: Maybe OfferingTransaction
$sel:offeringTransaction:RenewOfferingResponse' :: RenewOfferingResponse -> Maybe OfferingTransaction
offeringTransaction} -> Maybe OfferingTransaction
offeringTransaction) (\s :: RenewOfferingResponse
s@RenewOfferingResponse' {} Maybe OfferingTransaction
a -> RenewOfferingResponse
s {$sel:offeringTransaction:RenewOfferingResponse' :: Maybe OfferingTransaction
offeringTransaction = Maybe OfferingTransaction
a} :: RenewOfferingResponse)

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

instance Prelude.NFData RenewOfferingResponse