{-# 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.BillingConductor.AssociatePricingRules
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Connects an array of @PricingRuleArns@ to a defined @PricingPlan@. The
-- maximum number @PricingRuleArn@ that can be associated in one call is
-- 30.
module Amazonka.BillingConductor.AssociatePricingRules
  ( -- * Creating a Request
    AssociatePricingRules (..),
    newAssociatePricingRules,

    -- * Request Lenses
    associatePricingRules_arn,
    associatePricingRules_pricingRuleArns,

    -- * Destructuring the Response
    AssociatePricingRulesResponse (..),
    newAssociatePricingRulesResponse,

    -- * Response Lenses
    associatePricingRulesResponse_arn,
    associatePricingRulesResponse_httpStatus,
  )
where

import Amazonka.BillingConductor.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociatePricingRules' smart constructor.
data AssociatePricingRules = AssociatePricingRules'
  { -- | The @PricingPlanArn@ that the @PricingRuleArns@ are associated with.
    AssociatePricingRules -> Text
arn :: Prelude.Text,
    -- | The @PricingRuleArns@ that are associated with the Pricing Plan.
    AssociatePricingRules -> NonEmpty Text
pricingRuleArns :: Prelude.NonEmpty Prelude.Text
  }
  deriving (AssociatePricingRules -> AssociatePricingRules -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociatePricingRules -> AssociatePricingRules -> Bool
$c/= :: AssociatePricingRules -> AssociatePricingRules -> Bool
== :: AssociatePricingRules -> AssociatePricingRules -> Bool
$c== :: AssociatePricingRules -> AssociatePricingRules -> Bool
Prelude.Eq, ReadPrec [AssociatePricingRules]
ReadPrec AssociatePricingRules
Int -> ReadS AssociatePricingRules
ReadS [AssociatePricingRules]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociatePricingRules]
$creadListPrec :: ReadPrec [AssociatePricingRules]
readPrec :: ReadPrec AssociatePricingRules
$creadPrec :: ReadPrec AssociatePricingRules
readList :: ReadS [AssociatePricingRules]
$creadList :: ReadS [AssociatePricingRules]
readsPrec :: Int -> ReadS AssociatePricingRules
$creadsPrec :: Int -> ReadS AssociatePricingRules
Prelude.Read, Int -> AssociatePricingRules -> ShowS
[AssociatePricingRules] -> ShowS
AssociatePricingRules -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociatePricingRules] -> ShowS
$cshowList :: [AssociatePricingRules] -> ShowS
show :: AssociatePricingRules -> String
$cshow :: AssociatePricingRules -> String
showsPrec :: Int -> AssociatePricingRules -> ShowS
$cshowsPrec :: Int -> AssociatePricingRules -> ShowS
Prelude.Show, forall x. Rep AssociatePricingRules x -> AssociatePricingRules
forall x. AssociatePricingRules -> Rep AssociatePricingRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociatePricingRules x -> AssociatePricingRules
$cfrom :: forall x. AssociatePricingRules -> Rep AssociatePricingRules x
Prelude.Generic)

-- |
-- Create a value of 'AssociatePricingRules' 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', 'associatePricingRules_arn' - The @PricingPlanArn@ that the @PricingRuleArns@ are associated with.
--
-- 'pricingRuleArns', 'associatePricingRules_pricingRuleArns' - The @PricingRuleArns@ that are associated with the Pricing Plan.
newAssociatePricingRules ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'pricingRuleArns'
  Prelude.NonEmpty Prelude.Text ->
  AssociatePricingRules
newAssociatePricingRules :: Text -> NonEmpty Text -> AssociatePricingRules
newAssociatePricingRules Text
pArn_ NonEmpty Text
pPricingRuleArns_ =
  AssociatePricingRules'
    { $sel:arn:AssociatePricingRules' :: Text
arn = Text
pArn_,
      $sel:pricingRuleArns:AssociatePricingRules' :: NonEmpty Text
pricingRuleArns =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pPricingRuleArns_
    }

-- | The @PricingPlanArn@ that the @PricingRuleArns@ are associated with.
associatePricingRules_arn :: Lens.Lens' AssociatePricingRules Prelude.Text
associatePricingRules_arn :: Lens' AssociatePricingRules Text
associatePricingRules_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociatePricingRules' {Text
arn :: Text
$sel:arn:AssociatePricingRules' :: AssociatePricingRules -> Text
arn} -> Text
arn) (\s :: AssociatePricingRules
s@AssociatePricingRules' {} Text
a -> AssociatePricingRules
s {$sel:arn:AssociatePricingRules' :: Text
arn = Text
a} :: AssociatePricingRules)

-- | The @PricingRuleArns@ that are associated with the Pricing Plan.
associatePricingRules_pricingRuleArns :: Lens.Lens' AssociatePricingRules (Prelude.NonEmpty Prelude.Text)
associatePricingRules_pricingRuleArns :: Lens' AssociatePricingRules (NonEmpty Text)
associatePricingRules_pricingRuleArns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociatePricingRules' {NonEmpty Text
pricingRuleArns :: NonEmpty Text
$sel:pricingRuleArns:AssociatePricingRules' :: AssociatePricingRules -> NonEmpty Text
pricingRuleArns} -> NonEmpty Text
pricingRuleArns) (\s :: AssociatePricingRules
s@AssociatePricingRules' {} NonEmpty Text
a -> AssociatePricingRules
s {$sel:pricingRuleArns:AssociatePricingRules' :: NonEmpty Text
pricingRuleArns = NonEmpty Text
a} :: AssociatePricingRules) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest AssociatePricingRules where
  type
    AWSResponse AssociatePricingRules =
      AssociatePricingRulesResponse
  request :: (Service -> Service)
-> AssociatePricingRules -> Request AssociatePricingRules
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociatePricingRules
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociatePricingRules)))
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 -> Int -> AssociatePricingRulesResponse
AssociatePricingRulesResponse'
            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
"Arn")
            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 AssociatePricingRules where
  hashWithSalt :: Int -> AssociatePricingRules -> Int
hashWithSalt Int
_salt AssociatePricingRules' {NonEmpty Text
Text
pricingRuleArns :: NonEmpty Text
arn :: Text
$sel:pricingRuleArns:AssociatePricingRules' :: AssociatePricingRules -> NonEmpty Text
$sel:arn:AssociatePricingRules' :: AssociatePricingRules -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
pricingRuleArns

instance Prelude.NFData AssociatePricingRules where
  rnf :: AssociatePricingRules -> ()
rnf AssociatePricingRules' {NonEmpty Text
Text
pricingRuleArns :: NonEmpty Text
arn :: Text
$sel:pricingRuleArns:AssociatePricingRules' :: AssociatePricingRules -> NonEmpty Text
$sel:arn:AssociatePricingRules' :: AssociatePricingRules -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
pricingRuleArns

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

instance Data.ToJSON AssociatePricingRules where
  toJSON :: AssociatePricingRules -> Value
toJSON AssociatePricingRules' {NonEmpty Text
Text
pricingRuleArns :: NonEmpty Text
arn :: Text
$sel:pricingRuleArns:AssociatePricingRules' :: AssociatePricingRules -> NonEmpty Text
$sel:arn:AssociatePricingRules' :: AssociatePricingRules -> 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),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"PricingRuleArns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
pricingRuleArns)
          ]
      )

instance Data.ToPath AssociatePricingRules where
  toPath :: AssociatePricingRules -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/associate-pricing-rules"

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

-- | /See:/ 'newAssociatePricingRulesResponse' smart constructor.
data AssociatePricingRulesResponse = AssociatePricingRulesResponse'
  { -- | The @PricingPlanArn@ that the @PricingRuleArns@ are associated with.
    AssociatePricingRulesResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    AssociatePricingRulesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AssociatePricingRulesResponse
-> AssociatePricingRulesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociatePricingRulesResponse
-> AssociatePricingRulesResponse -> Bool
$c/= :: AssociatePricingRulesResponse
-> AssociatePricingRulesResponse -> Bool
== :: AssociatePricingRulesResponse
-> AssociatePricingRulesResponse -> Bool
$c== :: AssociatePricingRulesResponse
-> AssociatePricingRulesResponse -> Bool
Prelude.Eq, ReadPrec [AssociatePricingRulesResponse]
ReadPrec AssociatePricingRulesResponse
Int -> ReadS AssociatePricingRulesResponse
ReadS [AssociatePricingRulesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociatePricingRulesResponse]
$creadListPrec :: ReadPrec [AssociatePricingRulesResponse]
readPrec :: ReadPrec AssociatePricingRulesResponse
$creadPrec :: ReadPrec AssociatePricingRulesResponse
readList :: ReadS [AssociatePricingRulesResponse]
$creadList :: ReadS [AssociatePricingRulesResponse]
readsPrec :: Int -> ReadS AssociatePricingRulesResponse
$creadsPrec :: Int -> ReadS AssociatePricingRulesResponse
Prelude.Read, Int -> AssociatePricingRulesResponse -> ShowS
[AssociatePricingRulesResponse] -> ShowS
AssociatePricingRulesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociatePricingRulesResponse] -> ShowS
$cshowList :: [AssociatePricingRulesResponse] -> ShowS
show :: AssociatePricingRulesResponse -> String
$cshow :: AssociatePricingRulesResponse -> String
showsPrec :: Int -> AssociatePricingRulesResponse -> ShowS
$cshowsPrec :: Int -> AssociatePricingRulesResponse -> ShowS
Prelude.Show, forall x.
Rep AssociatePricingRulesResponse x
-> AssociatePricingRulesResponse
forall x.
AssociatePricingRulesResponse
-> Rep AssociatePricingRulesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociatePricingRulesResponse x
-> AssociatePricingRulesResponse
$cfrom :: forall x.
AssociatePricingRulesResponse
-> Rep AssociatePricingRulesResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociatePricingRulesResponse' 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', 'associatePricingRulesResponse_arn' - The @PricingPlanArn@ that the @PricingRuleArns@ are associated with.
--
-- 'httpStatus', 'associatePricingRulesResponse_httpStatus' - The response's http status code.
newAssociatePricingRulesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociatePricingRulesResponse
newAssociatePricingRulesResponse :: Int -> AssociatePricingRulesResponse
newAssociatePricingRulesResponse Int
pHttpStatus_ =
  AssociatePricingRulesResponse'
    { $sel:arn:AssociatePricingRulesResponse' :: Maybe Text
arn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociatePricingRulesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @PricingPlanArn@ that the @PricingRuleArns@ are associated with.
associatePricingRulesResponse_arn :: Lens.Lens' AssociatePricingRulesResponse (Prelude.Maybe Prelude.Text)
associatePricingRulesResponse_arn :: Lens' AssociatePricingRulesResponse (Maybe Text)
associatePricingRulesResponse_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociatePricingRulesResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:AssociatePricingRulesResponse' :: AssociatePricingRulesResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: AssociatePricingRulesResponse
s@AssociatePricingRulesResponse' {} Maybe Text
a -> AssociatePricingRulesResponse
s {$sel:arn:AssociatePricingRulesResponse' :: Maybe Text
arn = Maybe Text
a} :: AssociatePricingRulesResponse)

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

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