{-# 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.XRay.UpdateSamplingRule
-- 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)
--
-- Modifies a sampling rule\'s configuration.
module Amazonka.XRay.UpdateSamplingRule
  ( -- * Creating a Request
    UpdateSamplingRule (..),
    newUpdateSamplingRule,

    -- * Request Lenses
    updateSamplingRule_samplingRuleUpdate,

    -- * Destructuring the Response
    UpdateSamplingRuleResponse (..),
    newUpdateSamplingRuleResponse,

    -- * Response Lenses
    updateSamplingRuleResponse_samplingRuleRecord,
    updateSamplingRuleResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.XRay.Types

-- | /See:/ 'newUpdateSamplingRule' smart constructor.
data UpdateSamplingRule = UpdateSamplingRule'
  { -- | The rule and fields to change.
    UpdateSamplingRule -> SamplingRuleUpdate
samplingRuleUpdate :: SamplingRuleUpdate
  }
  deriving (UpdateSamplingRule -> UpdateSamplingRule -> Bool
(UpdateSamplingRule -> UpdateSamplingRule -> Bool)
-> (UpdateSamplingRule -> UpdateSamplingRule -> Bool)
-> Eq UpdateSamplingRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateSamplingRule -> UpdateSamplingRule -> Bool
$c/= :: UpdateSamplingRule -> UpdateSamplingRule -> Bool
== :: UpdateSamplingRule -> UpdateSamplingRule -> Bool
$c== :: UpdateSamplingRule -> UpdateSamplingRule -> Bool
Prelude.Eq, ReadPrec [UpdateSamplingRule]
ReadPrec UpdateSamplingRule
Int -> ReadS UpdateSamplingRule
ReadS [UpdateSamplingRule]
(Int -> ReadS UpdateSamplingRule)
-> ReadS [UpdateSamplingRule]
-> ReadPrec UpdateSamplingRule
-> ReadPrec [UpdateSamplingRule]
-> Read UpdateSamplingRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateSamplingRule]
$creadListPrec :: ReadPrec [UpdateSamplingRule]
readPrec :: ReadPrec UpdateSamplingRule
$creadPrec :: ReadPrec UpdateSamplingRule
readList :: ReadS [UpdateSamplingRule]
$creadList :: ReadS [UpdateSamplingRule]
readsPrec :: Int -> ReadS UpdateSamplingRule
$creadsPrec :: Int -> ReadS UpdateSamplingRule
Prelude.Read, Int -> UpdateSamplingRule -> ShowS
[UpdateSamplingRule] -> ShowS
UpdateSamplingRule -> String
(Int -> UpdateSamplingRule -> ShowS)
-> (UpdateSamplingRule -> String)
-> ([UpdateSamplingRule] -> ShowS)
-> Show UpdateSamplingRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateSamplingRule] -> ShowS
$cshowList :: [UpdateSamplingRule] -> ShowS
show :: UpdateSamplingRule -> String
$cshow :: UpdateSamplingRule -> String
showsPrec :: Int -> UpdateSamplingRule -> ShowS
$cshowsPrec :: Int -> UpdateSamplingRule -> ShowS
Prelude.Show, (forall x. UpdateSamplingRule -> Rep UpdateSamplingRule x)
-> (forall x. Rep UpdateSamplingRule x -> UpdateSamplingRule)
-> Generic UpdateSamplingRule
forall x. Rep UpdateSamplingRule x -> UpdateSamplingRule
forall x. UpdateSamplingRule -> Rep UpdateSamplingRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateSamplingRule x -> UpdateSamplingRule
$cfrom :: forall x. UpdateSamplingRule -> Rep UpdateSamplingRule x
Prelude.Generic)

-- |
-- Create a value of 'UpdateSamplingRule' 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:
--
-- 'samplingRuleUpdate', 'updateSamplingRule_samplingRuleUpdate' - The rule and fields to change.
newUpdateSamplingRule ::
  -- | 'samplingRuleUpdate'
  SamplingRuleUpdate ->
  UpdateSamplingRule
newUpdateSamplingRule :: SamplingRuleUpdate -> UpdateSamplingRule
newUpdateSamplingRule SamplingRuleUpdate
pSamplingRuleUpdate_ =
  UpdateSamplingRule' :: SamplingRuleUpdate -> UpdateSamplingRule
UpdateSamplingRule'
    { $sel:samplingRuleUpdate:UpdateSamplingRule' :: SamplingRuleUpdate
samplingRuleUpdate =
        SamplingRuleUpdate
pSamplingRuleUpdate_
    }

-- | The rule and fields to change.
updateSamplingRule_samplingRuleUpdate :: Lens.Lens' UpdateSamplingRule SamplingRuleUpdate
updateSamplingRule_samplingRuleUpdate :: (SamplingRuleUpdate -> f SamplingRuleUpdate)
-> UpdateSamplingRule -> f UpdateSamplingRule
updateSamplingRule_samplingRuleUpdate = (UpdateSamplingRule -> SamplingRuleUpdate)
-> (UpdateSamplingRule -> SamplingRuleUpdate -> UpdateSamplingRule)
-> Lens
     UpdateSamplingRule
     UpdateSamplingRule
     SamplingRuleUpdate
     SamplingRuleUpdate
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateSamplingRule' {SamplingRuleUpdate
samplingRuleUpdate :: SamplingRuleUpdate
$sel:samplingRuleUpdate:UpdateSamplingRule' :: UpdateSamplingRule -> SamplingRuleUpdate
samplingRuleUpdate} -> SamplingRuleUpdate
samplingRuleUpdate) (\s :: UpdateSamplingRule
s@UpdateSamplingRule' {} SamplingRuleUpdate
a -> UpdateSamplingRule
s {$sel:samplingRuleUpdate:UpdateSamplingRule' :: SamplingRuleUpdate
samplingRuleUpdate = SamplingRuleUpdate
a} :: UpdateSamplingRule)

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

instance Prelude.NFData UpdateSamplingRule

instance Core.ToHeaders UpdateSamplingRule where
  toHeaders :: UpdateSamplingRule -> ResponseHeaders
toHeaders = ResponseHeaders -> UpdateSamplingRule -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON UpdateSamplingRule where
  toJSON :: UpdateSamplingRule -> Value
toJSON UpdateSamplingRule' {SamplingRuleUpdate
samplingRuleUpdate :: SamplingRuleUpdate
$sel:samplingRuleUpdate:UpdateSamplingRule' :: UpdateSamplingRule -> SamplingRuleUpdate
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Key
"SamplingRuleUpdate" Key -> SamplingRuleUpdate -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= SamplingRuleUpdate
samplingRuleUpdate)
          ]
      )

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

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

-- | /See:/ 'newUpdateSamplingRuleResponse' smart constructor.
data UpdateSamplingRuleResponse = UpdateSamplingRuleResponse'
  { -- | The updated rule definition and metadata.
    UpdateSamplingRuleResponse -> Maybe SamplingRuleRecord
samplingRuleRecord :: Prelude.Maybe SamplingRuleRecord,
    -- | The response's http status code.
    UpdateSamplingRuleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateSamplingRuleResponse -> UpdateSamplingRuleResponse -> Bool
(UpdateSamplingRuleResponse -> UpdateSamplingRuleResponse -> Bool)
-> (UpdateSamplingRuleResponse
    -> UpdateSamplingRuleResponse -> Bool)
-> Eq UpdateSamplingRuleResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateSamplingRuleResponse -> UpdateSamplingRuleResponse -> Bool
$c/= :: UpdateSamplingRuleResponse -> UpdateSamplingRuleResponse -> Bool
== :: UpdateSamplingRuleResponse -> UpdateSamplingRuleResponse -> Bool
$c== :: UpdateSamplingRuleResponse -> UpdateSamplingRuleResponse -> Bool
Prelude.Eq, ReadPrec [UpdateSamplingRuleResponse]
ReadPrec UpdateSamplingRuleResponse
Int -> ReadS UpdateSamplingRuleResponse
ReadS [UpdateSamplingRuleResponse]
(Int -> ReadS UpdateSamplingRuleResponse)
-> ReadS [UpdateSamplingRuleResponse]
-> ReadPrec UpdateSamplingRuleResponse
-> ReadPrec [UpdateSamplingRuleResponse]
-> Read UpdateSamplingRuleResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateSamplingRuleResponse]
$creadListPrec :: ReadPrec [UpdateSamplingRuleResponse]
readPrec :: ReadPrec UpdateSamplingRuleResponse
$creadPrec :: ReadPrec UpdateSamplingRuleResponse
readList :: ReadS [UpdateSamplingRuleResponse]
$creadList :: ReadS [UpdateSamplingRuleResponse]
readsPrec :: Int -> ReadS UpdateSamplingRuleResponse
$creadsPrec :: Int -> ReadS UpdateSamplingRuleResponse
Prelude.Read, Int -> UpdateSamplingRuleResponse -> ShowS
[UpdateSamplingRuleResponse] -> ShowS
UpdateSamplingRuleResponse -> String
(Int -> UpdateSamplingRuleResponse -> ShowS)
-> (UpdateSamplingRuleResponse -> String)
-> ([UpdateSamplingRuleResponse] -> ShowS)
-> Show UpdateSamplingRuleResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateSamplingRuleResponse] -> ShowS
$cshowList :: [UpdateSamplingRuleResponse] -> ShowS
show :: UpdateSamplingRuleResponse -> String
$cshow :: UpdateSamplingRuleResponse -> String
showsPrec :: Int -> UpdateSamplingRuleResponse -> ShowS
$cshowsPrec :: Int -> UpdateSamplingRuleResponse -> ShowS
Prelude.Show, (forall x.
 UpdateSamplingRuleResponse -> Rep UpdateSamplingRuleResponse x)
-> (forall x.
    Rep UpdateSamplingRuleResponse x -> UpdateSamplingRuleResponse)
-> Generic UpdateSamplingRuleResponse
forall x.
Rep UpdateSamplingRuleResponse x -> UpdateSamplingRuleResponse
forall x.
UpdateSamplingRuleResponse -> Rep UpdateSamplingRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateSamplingRuleResponse x -> UpdateSamplingRuleResponse
$cfrom :: forall x.
UpdateSamplingRuleResponse -> Rep UpdateSamplingRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateSamplingRuleResponse' 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:
--
-- 'samplingRuleRecord', 'updateSamplingRuleResponse_samplingRuleRecord' - The updated rule definition and metadata.
--
-- 'httpStatus', 'updateSamplingRuleResponse_httpStatus' - The response's http status code.
newUpdateSamplingRuleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateSamplingRuleResponse
newUpdateSamplingRuleResponse :: Int -> UpdateSamplingRuleResponse
newUpdateSamplingRuleResponse Int
pHttpStatus_ =
  UpdateSamplingRuleResponse' :: Maybe SamplingRuleRecord -> Int -> UpdateSamplingRuleResponse
UpdateSamplingRuleResponse'
    { $sel:samplingRuleRecord:UpdateSamplingRuleResponse' :: Maybe SamplingRuleRecord
samplingRuleRecord =
        Maybe SamplingRuleRecord
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateSamplingRuleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The updated rule definition and metadata.
updateSamplingRuleResponse_samplingRuleRecord :: Lens.Lens' UpdateSamplingRuleResponse (Prelude.Maybe SamplingRuleRecord)
updateSamplingRuleResponse_samplingRuleRecord :: (Maybe SamplingRuleRecord -> f (Maybe SamplingRuleRecord))
-> UpdateSamplingRuleResponse -> f UpdateSamplingRuleResponse
updateSamplingRuleResponse_samplingRuleRecord = (UpdateSamplingRuleResponse -> Maybe SamplingRuleRecord)
-> (UpdateSamplingRuleResponse
    -> Maybe SamplingRuleRecord -> UpdateSamplingRuleResponse)
-> Lens
     UpdateSamplingRuleResponse
     UpdateSamplingRuleResponse
     (Maybe SamplingRuleRecord)
     (Maybe SamplingRuleRecord)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateSamplingRuleResponse' {Maybe SamplingRuleRecord
samplingRuleRecord :: Maybe SamplingRuleRecord
$sel:samplingRuleRecord:UpdateSamplingRuleResponse' :: UpdateSamplingRuleResponse -> Maybe SamplingRuleRecord
samplingRuleRecord} -> Maybe SamplingRuleRecord
samplingRuleRecord) (\s :: UpdateSamplingRuleResponse
s@UpdateSamplingRuleResponse' {} Maybe SamplingRuleRecord
a -> UpdateSamplingRuleResponse
s {$sel:samplingRuleRecord:UpdateSamplingRuleResponse' :: Maybe SamplingRuleRecord
samplingRuleRecord = Maybe SamplingRuleRecord
a} :: UpdateSamplingRuleResponse)

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

instance Prelude.NFData UpdateSamplingRuleResponse