{-# 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.ListOfferingTransactions
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns a list of all historical purchases, renewals, and system renewal
-- transactions for an AWS account. The list is paginated and ordered by a
-- descending timestamp (most recent transactions are first). 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>.
--
-- This operation returns paginated results.
module Amazonka.DeviceFarm.ListOfferingTransactions
  ( -- * Creating a Request
    ListOfferingTransactions (..),
    newListOfferingTransactions,

    -- * Request Lenses
    listOfferingTransactions_nextToken,

    -- * Destructuring the Response
    ListOfferingTransactionsResponse (..),
    newListOfferingTransactionsResponse,

    -- * Response Lenses
    listOfferingTransactionsResponse_nextToken,
    listOfferingTransactionsResponse_offeringTransactions,
    listOfferingTransactionsResponse_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 list the offering transaction history.
--
-- /See:/ 'newListOfferingTransactions' smart constructor.
data ListOfferingTransactions = ListOfferingTransactions'
  { -- | An identifier that was returned from the previous call to this
    -- operation, which can be used to return the next set of items in the
    -- list.
    ListOfferingTransactions -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListOfferingTransactions -> ListOfferingTransactions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListOfferingTransactions -> ListOfferingTransactions -> Bool
$c/= :: ListOfferingTransactions -> ListOfferingTransactions -> Bool
== :: ListOfferingTransactions -> ListOfferingTransactions -> Bool
$c== :: ListOfferingTransactions -> ListOfferingTransactions -> Bool
Prelude.Eq, ReadPrec [ListOfferingTransactions]
ReadPrec ListOfferingTransactions
Int -> ReadS ListOfferingTransactions
ReadS [ListOfferingTransactions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListOfferingTransactions]
$creadListPrec :: ReadPrec [ListOfferingTransactions]
readPrec :: ReadPrec ListOfferingTransactions
$creadPrec :: ReadPrec ListOfferingTransactions
readList :: ReadS [ListOfferingTransactions]
$creadList :: ReadS [ListOfferingTransactions]
readsPrec :: Int -> ReadS ListOfferingTransactions
$creadsPrec :: Int -> ReadS ListOfferingTransactions
Prelude.Read, Int -> ListOfferingTransactions -> ShowS
[ListOfferingTransactions] -> ShowS
ListOfferingTransactions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListOfferingTransactions] -> ShowS
$cshowList :: [ListOfferingTransactions] -> ShowS
show :: ListOfferingTransactions -> String
$cshow :: ListOfferingTransactions -> String
showsPrec :: Int -> ListOfferingTransactions -> ShowS
$cshowsPrec :: Int -> ListOfferingTransactions -> ShowS
Prelude.Show, forall x.
Rep ListOfferingTransactions x -> ListOfferingTransactions
forall x.
ListOfferingTransactions -> Rep ListOfferingTransactions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListOfferingTransactions x -> ListOfferingTransactions
$cfrom :: forall x.
ListOfferingTransactions -> Rep ListOfferingTransactions x
Prelude.Generic)

-- |
-- Create a value of 'ListOfferingTransactions' 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:
--
-- 'nextToken', 'listOfferingTransactions_nextToken' - An identifier that was returned from the previous call to this
-- operation, which can be used to return the next set of items in the
-- list.
newListOfferingTransactions ::
  ListOfferingTransactions
newListOfferingTransactions :: ListOfferingTransactions
newListOfferingTransactions =
  ListOfferingTransactions'
    { $sel:nextToken:ListOfferingTransactions' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing
    }

-- | An identifier that was returned from the previous call to this
-- operation, which can be used to return the next set of items in the
-- list.
listOfferingTransactions_nextToken :: Lens.Lens' ListOfferingTransactions (Prelude.Maybe Prelude.Text)
listOfferingTransactions_nextToken :: Lens' ListOfferingTransactions (Maybe Text)
listOfferingTransactions_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOfferingTransactions' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListOfferingTransactions' :: ListOfferingTransactions -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListOfferingTransactions
s@ListOfferingTransactions' {} Maybe Text
a -> ListOfferingTransactions
s {$sel:nextToken:ListOfferingTransactions' :: Maybe Text
nextToken = Maybe Text
a} :: ListOfferingTransactions)

instance Core.AWSPager ListOfferingTransactions where
  page :: ListOfferingTransactions
-> AWSResponse ListOfferingTransactions
-> Maybe ListOfferingTransactions
page ListOfferingTransactions
rq AWSResponse ListOfferingTransactions
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListOfferingTransactions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListOfferingTransactionsResponse (Maybe Text)
listOfferingTransactionsResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListOfferingTransactions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens'
  ListOfferingTransactionsResponse (Maybe [OfferingTransaction])
listOfferingTransactionsResponse_offeringTransactions
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListOfferingTransactions
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListOfferingTransactions (Maybe Text)
listOfferingTransactions_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListOfferingTransactions
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListOfferingTransactionsResponse (Maybe Text)
listOfferingTransactionsResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListOfferingTransactions where
  type
    AWSResponse ListOfferingTransactions =
      ListOfferingTransactionsResponse
  request :: (Service -> Service)
-> ListOfferingTransactions -> Request ListOfferingTransactions
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 ListOfferingTransactions
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListOfferingTransactions)))
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 Text
-> Maybe [OfferingTransaction]
-> Int
-> ListOfferingTransactionsResponse
ListOfferingTransactionsResponse'
            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
"nextToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"offeringTransactions"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            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 ListOfferingTransactions where
  hashWithSalt :: Int -> ListOfferingTransactions -> Int
hashWithSalt Int
_salt ListOfferingTransactions' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListOfferingTransactions' :: ListOfferingTransactions -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

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

instance Data.ToHeaders ListOfferingTransactions where
  toHeaders :: ListOfferingTransactions -> 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.ListOfferingTransactions" ::
                          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 ListOfferingTransactions where
  toJSON :: ListOfferingTransactions -> Value
toJSON ListOfferingTransactions' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListOfferingTransactions' :: ListOfferingTransactions -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"nextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken]
      )

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

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

-- | Returns the transaction log of the specified offerings.
--
-- /See:/ 'newListOfferingTransactionsResponse' smart constructor.
data ListOfferingTransactionsResponse = ListOfferingTransactionsResponse'
  { -- | An identifier that was returned from the previous call to this
    -- operation, which can be used to return the next set of items in the
    -- list.
    ListOfferingTransactionsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The audit log of subscriptions you have purchased and modified through
    -- AWS Device Farm.
    ListOfferingTransactionsResponse -> Maybe [OfferingTransaction]
offeringTransactions :: Prelude.Maybe [OfferingTransaction],
    -- | The response's http status code.
    ListOfferingTransactionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListOfferingTransactionsResponse
-> ListOfferingTransactionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListOfferingTransactionsResponse
-> ListOfferingTransactionsResponse -> Bool
$c/= :: ListOfferingTransactionsResponse
-> ListOfferingTransactionsResponse -> Bool
== :: ListOfferingTransactionsResponse
-> ListOfferingTransactionsResponse -> Bool
$c== :: ListOfferingTransactionsResponse
-> ListOfferingTransactionsResponse -> Bool
Prelude.Eq, ReadPrec [ListOfferingTransactionsResponse]
ReadPrec ListOfferingTransactionsResponse
Int -> ReadS ListOfferingTransactionsResponse
ReadS [ListOfferingTransactionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListOfferingTransactionsResponse]
$creadListPrec :: ReadPrec [ListOfferingTransactionsResponse]
readPrec :: ReadPrec ListOfferingTransactionsResponse
$creadPrec :: ReadPrec ListOfferingTransactionsResponse
readList :: ReadS [ListOfferingTransactionsResponse]
$creadList :: ReadS [ListOfferingTransactionsResponse]
readsPrec :: Int -> ReadS ListOfferingTransactionsResponse
$creadsPrec :: Int -> ReadS ListOfferingTransactionsResponse
Prelude.Read, Int -> ListOfferingTransactionsResponse -> ShowS
[ListOfferingTransactionsResponse] -> ShowS
ListOfferingTransactionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListOfferingTransactionsResponse] -> ShowS
$cshowList :: [ListOfferingTransactionsResponse] -> ShowS
show :: ListOfferingTransactionsResponse -> String
$cshow :: ListOfferingTransactionsResponse -> String
showsPrec :: Int -> ListOfferingTransactionsResponse -> ShowS
$cshowsPrec :: Int -> ListOfferingTransactionsResponse -> ShowS
Prelude.Show, forall x.
Rep ListOfferingTransactionsResponse x
-> ListOfferingTransactionsResponse
forall x.
ListOfferingTransactionsResponse
-> Rep ListOfferingTransactionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListOfferingTransactionsResponse x
-> ListOfferingTransactionsResponse
$cfrom :: forall x.
ListOfferingTransactionsResponse
-> Rep ListOfferingTransactionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListOfferingTransactionsResponse' 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:
--
-- 'nextToken', 'listOfferingTransactionsResponse_nextToken' - An identifier that was returned from the previous call to this
-- operation, which can be used to return the next set of items in the
-- list.
--
-- 'offeringTransactions', 'listOfferingTransactionsResponse_offeringTransactions' - The audit log of subscriptions you have purchased and modified through
-- AWS Device Farm.
--
-- 'httpStatus', 'listOfferingTransactionsResponse_httpStatus' - The response's http status code.
newListOfferingTransactionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListOfferingTransactionsResponse
newListOfferingTransactionsResponse :: Int -> ListOfferingTransactionsResponse
newListOfferingTransactionsResponse Int
pHttpStatus_ =
  ListOfferingTransactionsResponse'
    { $sel:nextToken:ListOfferingTransactionsResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:offeringTransactions:ListOfferingTransactionsResponse' :: Maybe [OfferingTransaction]
offeringTransactions = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListOfferingTransactionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An identifier that was returned from the previous call to this
-- operation, which can be used to return the next set of items in the
-- list.
listOfferingTransactionsResponse_nextToken :: Lens.Lens' ListOfferingTransactionsResponse (Prelude.Maybe Prelude.Text)
listOfferingTransactionsResponse_nextToken :: Lens' ListOfferingTransactionsResponse (Maybe Text)
listOfferingTransactionsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOfferingTransactionsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListOfferingTransactionsResponse' :: ListOfferingTransactionsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListOfferingTransactionsResponse
s@ListOfferingTransactionsResponse' {} Maybe Text
a -> ListOfferingTransactionsResponse
s {$sel:nextToken:ListOfferingTransactionsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListOfferingTransactionsResponse)

-- | The audit log of subscriptions you have purchased and modified through
-- AWS Device Farm.
listOfferingTransactionsResponse_offeringTransactions :: Lens.Lens' ListOfferingTransactionsResponse (Prelude.Maybe [OfferingTransaction])
listOfferingTransactionsResponse_offeringTransactions :: Lens'
  ListOfferingTransactionsResponse (Maybe [OfferingTransaction])
listOfferingTransactionsResponse_offeringTransactions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListOfferingTransactionsResponse' {Maybe [OfferingTransaction]
offeringTransactions :: Maybe [OfferingTransaction]
$sel:offeringTransactions:ListOfferingTransactionsResponse' :: ListOfferingTransactionsResponse -> Maybe [OfferingTransaction]
offeringTransactions} -> Maybe [OfferingTransaction]
offeringTransactions) (\s :: ListOfferingTransactionsResponse
s@ListOfferingTransactionsResponse' {} Maybe [OfferingTransaction]
a -> ListOfferingTransactionsResponse
s {$sel:offeringTransactions:ListOfferingTransactionsResponse' :: Maybe [OfferingTransaction]
offeringTransactions = Maybe [OfferingTransaction]
a} :: ListOfferingTransactionsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    ListOfferingTransactionsResponse
  where
  rnf :: ListOfferingTransactionsResponse -> ()
rnf ListOfferingTransactionsResponse' {Int
Maybe [OfferingTransaction]
Maybe Text
httpStatus :: Int
offeringTransactions :: Maybe [OfferingTransaction]
nextToken :: Maybe Text
$sel:httpStatus:ListOfferingTransactionsResponse' :: ListOfferingTransactionsResponse -> Int
$sel:offeringTransactions:ListOfferingTransactionsResponse' :: ListOfferingTransactionsResponse -> Maybe [OfferingTransaction]
$sel:nextToken:ListOfferingTransactionsResponse' :: ListOfferingTransactionsResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [OfferingTransaction]
offeringTransactions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus