{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.MarketplaceMetering.Types
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.MarketplaceMetering.Types
  ( -- * Service Configuration
    defaultService,

    -- * Errors
    _CustomerNotEntitledException,
    _DisabledApiException,
    _DuplicateRequestException,
    _ExpiredTokenException,
    _InternalServiceErrorException,
    _InvalidCustomerIdentifierException,
    _InvalidEndpointRegionException,
    _InvalidProductCodeException,
    _InvalidPublicKeyVersionException,
    _InvalidRegionException,
    _InvalidTagException,
    _InvalidTokenException,
    _InvalidUsageAllocationsException,
    _InvalidUsageDimensionException,
    _PlatformNotSupportedException,
    _ThrottlingException,
    _TimestampOutOfBoundsException,

    -- * UsageRecordResultStatus
    UsageRecordResultStatus (..),

    -- * Tag
    Tag (..),
    newTag,
    tag_key,
    tag_value,

    -- * UsageAllocation
    UsageAllocation (..),
    newUsageAllocation,
    usageAllocation_tags,
    usageAllocation_allocatedUsageQuantity,

    -- * UsageRecord
    UsageRecord (..),
    newUsageRecord,
    usageRecord_quantity,
    usageRecord_usageAllocations,
    usageRecord_timestamp,
    usageRecord_customerIdentifier,
    usageRecord_dimension,

    -- * UsageRecordResult
    UsageRecordResult (..),
    newUsageRecordResult,
    usageRecordResult_meteringRecordId,
    usageRecordResult_status,
    usageRecordResult_usageRecord,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import Amazonka.MarketplaceMetering.Types.Tag
import Amazonka.MarketplaceMetering.Types.UsageAllocation
import Amazonka.MarketplaceMetering.Types.UsageRecord
import Amazonka.MarketplaceMetering.Types.UsageRecordResult
import Amazonka.MarketplaceMetering.Types.UsageRecordResultStatus
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Sign.V4 as Sign

-- | API version @2016-01-14@ of the Amazon Marketplace Metering SDK configuration.
defaultService :: Core.Service
defaultService :: Service
defaultService =
  Core.Service
    { $sel:abbrev:Service :: Abbrev
Core.abbrev = Abbrev
"MarketplaceMetering",
      $sel:signer:Service :: Signer
Core.signer = Signer
Sign.v4,
      $sel:endpointPrefix:Service :: ByteString
Core.endpointPrefix = ByteString
"metering.marketplace",
      $sel:signingName:Service :: ByteString
Core.signingName = ByteString
"aws-marketplace",
      $sel:version:Service :: ByteString
Core.version = ByteString
"2016-01-14",
      $sel:s3AddressingStyle:Service :: S3AddressingStyle
Core.s3AddressingStyle = S3AddressingStyle
Core.S3AddressingStyleAuto,
      $sel:endpoint:Service :: Region -> Endpoint
Core.endpoint = Service -> Region -> Endpoint
Core.defaultEndpoint Service
defaultService,
      $sel:timeout:Service :: Maybe Seconds
Core.timeout = forall a. a -> Maybe a
Prelude.Just Seconds
70,
      $sel:check:Service :: Status -> Bool
Core.check = Status -> Bool
Core.statusSuccess,
      $sel:error:Service :: Status -> [Header] -> ByteStringLazy -> Error
Core.error =
        Abbrev -> Status -> [Header] -> ByteStringLazy -> Error
Core.parseJSONError Abbrev
"MarketplaceMetering",
      $sel:retry:Service :: Retry
Core.retry = Retry
retry
    }
  where
    retry :: Retry
retry =
      Core.Exponential
        { $sel:base:Exponential :: Double
Core.base = Double
5.0e-2,
          $sel:growth:Exponential :: Int
Core.growth = Int
2,
          $sel:attempts:Exponential :: Int
Core.attempts = Int
5,
          $sel:check:Exponential :: ServiceError -> Maybe Text
Core.check = forall {a}. IsString a => ServiceError -> Maybe a
check
        }
    check :: ServiceError -> Maybe a
check ServiceError
e
      | forall s a. Getting Any s a -> s -> Bool
Lens.has (forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
502) ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"bad_gateway"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has (forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
504) ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"gateway_timeout"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has (forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
500) ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"general_server_error"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has (forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
509) ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"limit_exceeded"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has
          ( forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
ErrorCode -> Optic' p f ServiceError ServiceError
Core.hasCode ErrorCode
"RequestThrottledException"
              forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
400
          )
          ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"request_throttled_exception"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has (forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
503) ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"service_unavailable"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has
          ( forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
ErrorCode -> Optic' p f ServiceError ServiceError
Core.hasCode ErrorCode
"ThrottledException"
              forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
400
          )
          ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"throttled_exception"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has
          ( forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
ErrorCode -> Optic' p f ServiceError ServiceError
Core.hasCode ErrorCode
"Throttling"
              forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
400
          )
          ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"throttling"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has
          ( forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
ErrorCode -> Optic' p f ServiceError ServiceError
Core.hasCode ErrorCode
"ThrottlingException"
              forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
400
          )
          ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"throttling_exception"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has
          ( forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
ErrorCode -> Optic' p f ServiceError ServiceError
Core.hasCode
              ErrorCode
"ProvisionedThroughputExceededException"
              forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
400
          )
          ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"throughput_exceeded"
      | forall s a. Getting Any s a -> s -> Bool
Lens.has (forall (f :: * -> *) (p :: * -> * -> *).
(Applicative f, Choice p) =>
Int -> Optic' p f ServiceError ServiceError
Core.hasStatus Int
429) ServiceError
e =
          forall a. a -> Maybe a
Prelude.Just a
"too_many_requests"
      | Bool
Prelude.otherwise = forall a. Maybe a
Prelude.Nothing

-- | Exception thrown when the customer does not have a valid subscription
-- for the product.
_CustomerNotEntitledException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_CustomerNotEntitledException :: forall a. AsError a => Fold a ServiceError
_CustomerNotEntitledException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"CustomerNotEntitledException"

-- | The API is disabled in the Region.
_DisabledApiException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_DisabledApiException :: forall a. AsError a => Fold a ServiceError
_DisabledApiException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"DisabledApiException"

-- | A metering record has already been emitted by the same EC2 instance, ECS
-- task, or EKS pod for the given {@usageDimension@, @timestamp@} with a
-- different @usageQuantity@.
_DuplicateRequestException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_DuplicateRequestException :: forall a. AsError a => Fold a ServiceError
_DuplicateRequestException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"DuplicateRequestException"

-- | The submitted registration token has expired. This can happen if the
-- buyer\'s browser takes too long to redirect to your page, the buyer has
-- resubmitted the registration token, or your application has held on to
-- the registration token for too long. Your SaaS registration website
-- should redeem this token as soon as it is submitted by the buyer\'s
-- browser.
_ExpiredTokenException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_ExpiredTokenException :: forall a. AsError a => Fold a ServiceError
_ExpiredTokenException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"ExpiredTokenException"

-- | An internal error has occurred. Retry your request. If the problem
-- persists, post a message with details on the AWS forums.
_InternalServiceErrorException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InternalServiceErrorException :: forall a. AsError a => Fold a ServiceError
_InternalServiceErrorException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InternalServiceErrorException"

-- | You have metered usage for a @CustomerIdentifier@ that does not exist.
_InvalidCustomerIdentifierException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidCustomerIdentifierException :: forall a. AsError a => Fold a ServiceError
_InvalidCustomerIdentifierException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidCustomerIdentifierException"

-- | The endpoint being called is in a AWS Region different from your EC2
-- instance, ECS task, or EKS pod. The Region of the Metering Service
-- endpoint and the AWS Region of the resource must match.
_InvalidEndpointRegionException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidEndpointRegionException :: forall a. AsError a => Fold a ServiceError
_InvalidEndpointRegionException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidEndpointRegionException"

-- | The product code passed does not match the product code used for
-- publishing the product.
_InvalidProductCodeException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidProductCodeException :: forall a. AsError a => Fold a ServiceError
_InvalidProductCodeException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidProductCodeException"

-- | Public Key version is invalid.
_InvalidPublicKeyVersionException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidPublicKeyVersionException :: forall a. AsError a => Fold a ServiceError
_InvalidPublicKeyVersionException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidPublicKeyVersionException"

-- | @RegisterUsage@ must be called in the same AWS Region the ECS task was
-- launched in. This prevents a container from hardcoding a Region (e.g.
-- withRegion(“us-east-1”) when calling @RegisterUsage@.
_InvalidRegionException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidRegionException :: forall a. AsError a => Fold a ServiceError
_InvalidRegionException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidRegionException"

-- | The tag is invalid, or the number of tags is greater than 5.
_InvalidTagException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidTagException :: forall a. AsError a => Fold a ServiceError
_InvalidTagException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidTagException"

-- | Registration token is invalid.
_InvalidTokenException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidTokenException :: forall a. AsError a => Fold a ServiceError
_InvalidTokenException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidTokenException"

-- | The usage allocation objects are invalid, or the number of allocations
-- is greater than 500 for a single usage record.
_InvalidUsageAllocationsException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidUsageAllocationsException :: forall a. AsError a => Fold a ServiceError
_InvalidUsageAllocationsException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidUsageAllocationsException"

-- | The usage dimension does not match one of the @UsageDimensions@
-- associated with products.
_InvalidUsageDimensionException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_InvalidUsageDimensionException :: forall a. AsError a => Fold a ServiceError
_InvalidUsageDimensionException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"InvalidUsageDimensionException"

-- | AWS Marketplace does not support metering usage from the underlying
-- platform. Currently, Amazon ECS, Amazon EKS, and AWS Fargate are
-- supported.
_PlatformNotSupportedException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_PlatformNotSupportedException :: forall a. AsError a => Fold a ServiceError
_PlatformNotSupportedException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"PlatformNotSupportedException"

-- | The calls to the API are throttled.
_ThrottlingException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_ThrottlingException :: forall a. AsError a => Fold a ServiceError
_ThrottlingException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"ThrottlingException"

-- | The @timestamp@ value passed in the @UsageRecord@ is out of allowed
-- range.
--
-- For @BatchMeterUsage@, if any of the records are outside of the allowed
-- range, the entire batch is not processed. You must remove invalid
-- records and try again.
_TimestampOutOfBoundsException :: (Core.AsError a) => Lens.Fold a Core.ServiceError
_TimestampOutOfBoundsException :: forall a. AsError a => Fold a ServiceError
_TimestampOutOfBoundsException =
  forall a. AsError a => Service -> ErrorCode -> Fold a ServiceError
Core._MatchServiceError
    Service
defaultService
    ErrorCode
"TimestampOutOfBoundsException"