{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.SamplingRule
-- 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)
module Amazonka.XRay.Types.SamplingRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A sampling rule that services use to decide whether to instrument a
-- request. Rule fields can match properties of the service, or properties
-- of a request. The service can ignore rules that don\'t match its
-- properties.
--
-- /See:/ 'newSamplingRule' smart constructor.
data SamplingRule = SamplingRule'
  { -- | The name of the sampling rule. Specify a rule by either name or ARN, but
    -- not both.
    SamplingRule -> Maybe Text
ruleName :: Prelude.Maybe Prelude.Text,
    -- | Matches attributes derived from the request.
    SamplingRule -> Maybe (HashMap Text Text)
attributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The ARN of the sampling rule. Specify a rule by either name or ARN, but
    -- not both.
    SamplingRule -> Maybe Text
ruleARN :: Prelude.Maybe Prelude.Text,
    -- | Matches the ARN of the Amazon Web Services resource on which the service
    -- runs.
    SamplingRule -> Text
resourceARN :: Prelude.Text,
    -- | The priority of the sampling rule.
    SamplingRule -> Natural
priority :: Prelude.Natural,
    -- | The percentage of matching requests to instrument, after the reservoir
    -- is exhausted.
    SamplingRule -> Double
fixedRate :: Prelude.Double,
    -- | A fixed number of matching requests to instrument per second, prior to
    -- applying the fixed rate. The reservoir is not used directly by services,
    -- but applies to all services using the rule collectively.
    SamplingRule -> Natural
reservoirSize :: Prelude.Natural,
    -- | Matches the @name@ that the service uses to identify itself in segments.
    SamplingRule -> Text
serviceName :: Prelude.Text,
    -- | Matches the @origin@ that the service uses to identify its type in
    -- segments.
    SamplingRule -> Text
serviceType :: Prelude.Text,
    -- | Matches the hostname from a request URL.
    SamplingRule -> Text
host :: Prelude.Text,
    -- | Matches the HTTP method of a request.
    SamplingRule -> Text
hTTPMethod :: Prelude.Text,
    -- | Matches the path from a request URL.
    SamplingRule -> Text
uRLPath :: Prelude.Text,
    -- | The version of the sampling rule format (@1@).
    SamplingRule -> Natural
version :: Prelude.Natural
  }
  deriving (SamplingRule -> SamplingRule -> Bool
(SamplingRule -> SamplingRule -> Bool)
-> (SamplingRule -> SamplingRule -> Bool) -> Eq SamplingRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SamplingRule -> SamplingRule -> Bool
$c/= :: SamplingRule -> SamplingRule -> Bool
== :: SamplingRule -> SamplingRule -> Bool
$c== :: SamplingRule -> SamplingRule -> Bool
Prelude.Eq, ReadPrec [SamplingRule]
ReadPrec SamplingRule
Int -> ReadS SamplingRule
ReadS [SamplingRule]
(Int -> ReadS SamplingRule)
-> ReadS [SamplingRule]
-> ReadPrec SamplingRule
-> ReadPrec [SamplingRule]
-> Read SamplingRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SamplingRule]
$creadListPrec :: ReadPrec [SamplingRule]
readPrec :: ReadPrec SamplingRule
$creadPrec :: ReadPrec SamplingRule
readList :: ReadS [SamplingRule]
$creadList :: ReadS [SamplingRule]
readsPrec :: Int -> ReadS SamplingRule
$creadsPrec :: Int -> ReadS SamplingRule
Prelude.Read, Int -> SamplingRule -> ShowS
[SamplingRule] -> ShowS
SamplingRule -> String
(Int -> SamplingRule -> ShowS)
-> (SamplingRule -> String)
-> ([SamplingRule] -> ShowS)
-> Show SamplingRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SamplingRule] -> ShowS
$cshowList :: [SamplingRule] -> ShowS
show :: SamplingRule -> String
$cshow :: SamplingRule -> String
showsPrec :: Int -> SamplingRule -> ShowS
$cshowsPrec :: Int -> SamplingRule -> ShowS
Prelude.Show, (forall x. SamplingRule -> Rep SamplingRule x)
-> (forall x. Rep SamplingRule x -> SamplingRule)
-> Generic SamplingRule
forall x. Rep SamplingRule x -> SamplingRule
forall x. SamplingRule -> Rep SamplingRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SamplingRule x -> SamplingRule
$cfrom :: forall x. SamplingRule -> Rep SamplingRule x
Prelude.Generic)

-- |
-- Create a value of 'SamplingRule' 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:
--
-- 'ruleName', 'samplingRule_ruleName' - The name of the sampling rule. Specify a rule by either name or ARN, but
-- not both.
--
-- 'attributes', 'samplingRule_attributes' - Matches attributes derived from the request.
--
-- 'ruleARN', 'samplingRule_ruleARN' - The ARN of the sampling rule. Specify a rule by either name or ARN, but
-- not both.
--
-- 'resourceARN', 'samplingRule_resourceARN' - Matches the ARN of the Amazon Web Services resource on which the service
-- runs.
--
-- 'priority', 'samplingRule_priority' - The priority of the sampling rule.
--
-- 'fixedRate', 'samplingRule_fixedRate' - The percentage of matching requests to instrument, after the reservoir
-- is exhausted.
--
-- 'reservoirSize', 'samplingRule_reservoirSize' - A fixed number of matching requests to instrument per second, prior to
-- applying the fixed rate. The reservoir is not used directly by services,
-- but applies to all services using the rule collectively.
--
-- 'serviceName', 'samplingRule_serviceName' - Matches the @name@ that the service uses to identify itself in segments.
--
-- 'serviceType', 'samplingRule_serviceType' - Matches the @origin@ that the service uses to identify its type in
-- segments.
--
-- 'host', 'samplingRule_host' - Matches the hostname from a request URL.
--
-- 'hTTPMethod', 'samplingRule_hTTPMethod' - Matches the HTTP method of a request.
--
-- 'uRLPath', 'samplingRule_uRLPath' - Matches the path from a request URL.
--
-- 'version', 'samplingRule_version' - The version of the sampling rule format (@1@).
newSamplingRule ::
  -- | 'resourceARN'
  Prelude.Text ->
  -- | 'priority'
  Prelude.Natural ->
  -- | 'fixedRate'
  Prelude.Double ->
  -- | 'reservoirSize'
  Prelude.Natural ->
  -- | 'serviceName'
  Prelude.Text ->
  -- | 'serviceType'
  Prelude.Text ->
  -- | 'host'
  Prelude.Text ->
  -- | 'hTTPMethod'
  Prelude.Text ->
  -- | 'uRLPath'
  Prelude.Text ->
  -- | 'version'
  Prelude.Natural ->
  SamplingRule
newSamplingRule :: Text
-> Natural
-> Double
-> Natural
-> Text
-> Text
-> Text
-> Text
-> Text
-> Natural
-> SamplingRule
newSamplingRule
  Text
pResourceARN_
  Natural
pPriority_
  Double
pFixedRate_
  Natural
pReservoirSize_
  Text
pServiceName_
  Text
pServiceType_
  Text
pHost_
  Text
pHTTPMethod_
  Text
pURLPath_
  Natural
pVersion_ =
    SamplingRule' :: Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe Text
-> Text
-> Natural
-> Double
-> Natural
-> Text
-> Text
-> Text
-> Text
-> Text
-> Natural
-> SamplingRule
SamplingRule'
      { $sel:ruleName:SamplingRule' :: Maybe Text
ruleName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:attributes:SamplingRule' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
        $sel:ruleARN:SamplingRule' :: Maybe Text
ruleARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:resourceARN:SamplingRule' :: Text
resourceARN = Text
pResourceARN_,
        $sel:priority:SamplingRule' :: Natural
priority = Natural
pPriority_,
        $sel:fixedRate:SamplingRule' :: Double
fixedRate = Double
pFixedRate_,
        $sel:reservoirSize:SamplingRule' :: Natural
reservoirSize = Natural
pReservoirSize_,
        $sel:serviceName:SamplingRule' :: Text
serviceName = Text
pServiceName_,
        $sel:serviceType:SamplingRule' :: Text
serviceType = Text
pServiceType_,
        $sel:host:SamplingRule' :: Text
host = Text
pHost_,
        $sel:hTTPMethod:SamplingRule' :: Text
hTTPMethod = Text
pHTTPMethod_,
        $sel:uRLPath:SamplingRule' :: Text
uRLPath = Text
pURLPath_,
        $sel:version:SamplingRule' :: Natural
version = Natural
pVersion_
      }

-- | The name of the sampling rule. Specify a rule by either name or ARN, but
-- not both.
samplingRule_ruleName :: Lens.Lens' SamplingRule (Prelude.Maybe Prelude.Text)
samplingRule_ruleName :: (Maybe Text -> f (Maybe Text)) -> SamplingRule -> f SamplingRule
samplingRule_ruleName = (SamplingRule -> Maybe Text)
-> (SamplingRule -> Maybe Text -> SamplingRule)
-> Lens SamplingRule SamplingRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Maybe Text
ruleName :: Maybe Text
$sel:ruleName:SamplingRule' :: SamplingRule -> Maybe Text
ruleName} -> Maybe Text
ruleName) (\s :: SamplingRule
s@SamplingRule' {} Maybe Text
a -> SamplingRule
s {$sel:ruleName:SamplingRule' :: Maybe Text
ruleName = Maybe Text
a} :: SamplingRule)

-- | Matches attributes derived from the request.
samplingRule_attributes :: Lens.Lens' SamplingRule (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
samplingRule_attributes :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> SamplingRule -> f SamplingRule
samplingRule_attributes = (SamplingRule -> Maybe (HashMap Text Text))
-> (SamplingRule -> Maybe (HashMap Text Text) -> SamplingRule)
-> Lens
     SamplingRule
     SamplingRule
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Maybe (HashMap Text Text)
attributes :: Maybe (HashMap Text Text)
$sel:attributes:SamplingRule' :: SamplingRule -> Maybe (HashMap Text Text)
attributes} -> Maybe (HashMap Text Text)
attributes) (\s :: SamplingRule
s@SamplingRule' {} Maybe (HashMap Text Text)
a -> SamplingRule
s {$sel:attributes:SamplingRule' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
a} :: SamplingRule) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> SamplingRule -> f SamplingRule)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> SamplingRule
-> f SamplingRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ARN of the sampling rule. Specify a rule by either name or ARN, but
-- not both.
samplingRule_ruleARN :: Lens.Lens' SamplingRule (Prelude.Maybe Prelude.Text)
samplingRule_ruleARN :: (Maybe Text -> f (Maybe Text)) -> SamplingRule -> f SamplingRule
samplingRule_ruleARN = (SamplingRule -> Maybe Text)
-> (SamplingRule -> Maybe Text -> SamplingRule)
-> Lens SamplingRule SamplingRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Maybe Text
ruleARN :: Maybe Text
$sel:ruleARN:SamplingRule' :: SamplingRule -> Maybe Text
ruleARN} -> Maybe Text
ruleARN) (\s :: SamplingRule
s@SamplingRule' {} Maybe Text
a -> SamplingRule
s {$sel:ruleARN:SamplingRule' :: Maybe Text
ruleARN = Maybe Text
a} :: SamplingRule)

-- | Matches the ARN of the Amazon Web Services resource on which the service
-- runs.
samplingRule_resourceARN :: Lens.Lens' SamplingRule Prelude.Text
samplingRule_resourceARN :: (Text -> f Text) -> SamplingRule -> f SamplingRule
samplingRule_resourceARN = (SamplingRule -> Text)
-> (SamplingRule -> Text -> SamplingRule)
-> Lens SamplingRule SamplingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Text
resourceARN :: Text
$sel:resourceARN:SamplingRule' :: SamplingRule -> Text
resourceARN} -> Text
resourceARN) (\s :: SamplingRule
s@SamplingRule' {} Text
a -> SamplingRule
s {$sel:resourceARN:SamplingRule' :: Text
resourceARN = Text
a} :: SamplingRule)

-- | The priority of the sampling rule.
samplingRule_priority :: Lens.Lens' SamplingRule Prelude.Natural
samplingRule_priority :: (Natural -> f Natural) -> SamplingRule -> f SamplingRule
samplingRule_priority = (SamplingRule -> Natural)
-> (SamplingRule -> Natural -> SamplingRule)
-> Lens SamplingRule SamplingRule Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Natural
priority :: Natural
$sel:priority:SamplingRule' :: SamplingRule -> Natural
priority} -> Natural
priority) (\s :: SamplingRule
s@SamplingRule' {} Natural
a -> SamplingRule
s {$sel:priority:SamplingRule' :: Natural
priority = Natural
a} :: SamplingRule)

-- | The percentage of matching requests to instrument, after the reservoir
-- is exhausted.
samplingRule_fixedRate :: Lens.Lens' SamplingRule Prelude.Double
samplingRule_fixedRate :: (Double -> f Double) -> SamplingRule -> f SamplingRule
samplingRule_fixedRate = (SamplingRule -> Double)
-> (SamplingRule -> Double -> SamplingRule)
-> Lens SamplingRule SamplingRule Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Double
fixedRate :: Double
$sel:fixedRate:SamplingRule' :: SamplingRule -> Double
fixedRate} -> Double
fixedRate) (\s :: SamplingRule
s@SamplingRule' {} Double
a -> SamplingRule
s {$sel:fixedRate:SamplingRule' :: Double
fixedRate = Double
a} :: SamplingRule)

-- | A fixed number of matching requests to instrument per second, prior to
-- applying the fixed rate. The reservoir is not used directly by services,
-- but applies to all services using the rule collectively.
samplingRule_reservoirSize :: Lens.Lens' SamplingRule Prelude.Natural
samplingRule_reservoirSize :: (Natural -> f Natural) -> SamplingRule -> f SamplingRule
samplingRule_reservoirSize = (SamplingRule -> Natural)
-> (SamplingRule -> Natural -> SamplingRule)
-> Lens SamplingRule SamplingRule Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Natural
reservoirSize :: Natural
$sel:reservoirSize:SamplingRule' :: SamplingRule -> Natural
reservoirSize} -> Natural
reservoirSize) (\s :: SamplingRule
s@SamplingRule' {} Natural
a -> SamplingRule
s {$sel:reservoirSize:SamplingRule' :: Natural
reservoirSize = Natural
a} :: SamplingRule)

-- | Matches the @name@ that the service uses to identify itself in segments.
samplingRule_serviceName :: Lens.Lens' SamplingRule Prelude.Text
samplingRule_serviceName :: (Text -> f Text) -> SamplingRule -> f SamplingRule
samplingRule_serviceName = (SamplingRule -> Text)
-> (SamplingRule -> Text -> SamplingRule)
-> Lens SamplingRule SamplingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Text
serviceName :: Text
$sel:serviceName:SamplingRule' :: SamplingRule -> Text
serviceName} -> Text
serviceName) (\s :: SamplingRule
s@SamplingRule' {} Text
a -> SamplingRule
s {$sel:serviceName:SamplingRule' :: Text
serviceName = Text
a} :: SamplingRule)

-- | Matches the @origin@ that the service uses to identify its type in
-- segments.
samplingRule_serviceType :: Lens.Lens' SamplingRule Prelude.Text
samplingRule_serviceType :: (Text -> f Text) -> SamplingRule -> f SamplingRule
samplingRule_serviceType = (SamplingRule -> Text)
-> (SamplingRule -> Text -> SamplingRule)
-> Lens SamplingRule SamplingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Text
serviceType :: Text
$sel:serviceType:SamplingRule' :: SamplingRule -> Text
serviceType} -> Text
serviceType) (\s :: SamplingRule
s@SamplingRule' {} Text
a -> SamplingRule
s {$sel:serviceType:SamplingRule' :: Text
serviceType = Text
a} :: SamplingRule)

-- | Matches the hostname from a request URL.
samplingRule_host :: Lens.Lens' SamplingRule Prelude.Text
samplingRule_host :: (Text -> f Text) -> SamplingRule -> f SamplingRule
samplingRule_host = (SamplingRule -> Text)
-> (SamplingRule -> Text -> SamplingRule)
-> Lens SamplingRule SamplingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Text
host :: Text
$sel:host:SamplingRule' :: SamplingRule -> Text
host} -> Text
host) (\s :: SamplingRule
s@SamplingRule' {} Text
a -> SamplingRule
s {$sel:host:SamplingRule' :: Text
host = Text
a} :: SamplingRule)

-- | Matches the HTTP method of a request.
samplingRule_hTTPMethod :: Lens.Lens' SamplingRule Prelude.Text
samplingRule_hTTPMethod :: (Text -> f Text) -> SamplingRule -> f SamplingRule
samplingRule_hTTPMethod = (SamplingRule -> Text)
-> (SamplingRule -> Text -> SamplingRule)
-> Lens SamplingRule SamplingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Text
hTTPMethod :: Text
$sel:hTTPMethod:SamplingRule' :: SamplingRule -> Text
hTTPMethod} -> Text
hTTPMethod) (\s :: SamplingRule
s@SamplingRule' {} Text
a -> SamplingRule
s {$sel:hTTPMethod:SamplingRule' :: Text
hTTPMethod = Text
a} :: SamplingRule)

-- | Matches the path from a request URL.
samplingRule_uRLPath :: Lens.Lens' SamplingRule Prelude.Text
samplingRule_uRLPath :: (Text -> f Text) -> SamplingRule -> f SamplingRule
samplingRule_uRLPath = (SamplingRule -> Text)
-> (SamplingRule -> Text -> SamplingRule)
-> Lens SamplingRule SamplingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Text
uRLPath :: Text
$sel:uRLPath:SamplingRule' :: SamplingRule -> Text
uRLPath} -> Text
uRLPath) (\s :: SamplingRule
s@SamplingRule' {} Text
a -> SamplingRule
s {$sel:uRLPath:SamplingRule' :: Text
uRLPath = Text
a} :: SamplingRule)

-- | The version of the sampling rule format (@1@).
samplingRule_version :: Lens.Lens' SamplingRule Prelude.Natural
samplingRule_version :: (Natural -> f Natural) -> SamplingRule -> f SamplingRule
samplingRule_version = (SamplingRule -> Natural)
-> (SamplingRule -> Natural -> SamplingRule)
-> Lens SamplingRule SamplingRule Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SamplingRule' {Natural
version :: Natural
$sel:version:SamplingRule' :: SamplingRule -> Natural
version} -> Natural
version) (\s :: SamplingRule
s@SamplingRule' {} Natural
a -> SamplingRule
s {$sel:version:SamplingRule' :: Natural
version = Natural
a} :: SamplingRule)

instance Core.FromJSON SamplingRule where
  parseJSON :: Value -> Parser SamplingRule
parseJSON =
    String
-> (Object -> Parser SamplingRule) -> Value -> Parser SamplingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SamplingRule"
      ( \Object
x ->
          Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe Text
-> Text
-> Natural
-> Double
-> Natural
-> Text
-> Text
-> Text
-> Text
-> Text
-> Natural
-> SamplingRule
SamplingRule'
            (Maybe Text
 -> Maybe (HashMap Text Text)
 -> Maybe Text
 -> Text
 -> Natural
 -> Double
 -> Natural
 -> Text
 -> Text
 -> Text
 -> Text
 -> Text
 -> Natural
 -> SamplingRule)
-> Parser (Maybe Text)
-> Parser
     (Maybe (HashMap Text Text)
      -> Maybe Text
      -> Text
      -> Natural
      -> Double
      -> Natural
      -> Text
      -> Text
      -> Text
      -> Text
      -> Text
      -> Natural
      -> SamplingRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RuleName")
            Parser
  (Maybe (HashMap Text Text)
   -> Maybe Text
   -> Text
   -> Natural
   -> Double
   -> Natural
   -> Text
   -> Text
   -> Text
   -> Text
   -> Text
   -> Natural
   -> SamplingRule)
-> Parser (Maybe (HashMap Text Text))
-> Parser
     (Maybe Text
      -> Text
      -> Natural
      -> Double
      -> Natural
      -> Text
      -> Text
      -> Text
      -> Text
      -> Text
      -> Natural
      -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Attributes" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Text
   -> Text
   -> Natural
   -> Double
   -> Natural
   -> Text
   -> Text
   -> Text
   -> Text
   -> Text
   -> Natural
   -> SamplingRule)
-> Parser (Maybe Text)
-> Parser
     (Text
      -> Natural
      -> Double
      -> Natural
      -> Text
      -> Text
      -> Text
      -> Text
      -> Text
      -> Natural
      -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RuleARN")
            Parser
  (Text
   -> Natural
   -> Double
   -> Natural
   -> Text
   -> Text
   -> Text
   -> Text
   -> Text
   -> Natural
   -> SamplingRule)
-> Parser Text
-> Parser
     (Natural
      -> Double
      -> Natural
      -> Text
      -> Text
      -> Text
      -> Text
      -> Text
      -> Natural
      -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ResourceARN")
            Parser
  (Natural
   -> Double
   -> Natural
   -> Text
   -> Text
   -> Text
   -> Text
   -> Text
   -> Natural
   -> SamplingRule)
-> Parser Natural
-> Parser
     (Double
      -> Natural
      -> Text
      -> Text
      -> Text
      -> Text
      -> Text
      -> Natural
      -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Priority")
            Parser
  (Double
   -> Natural
   -> Text
   -> Text
   -> Text
   -> Text
   -> Text
   -> Natural
   -> SamplingRule)
-> Parser Double
-> Parser
     (Natural
      -> Text -> Text -> Text -> Text -> Text -> Natural -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"FixedRate")
            Parser
  (Natural
   -> Text -> Text -> Text -> Text -> Text -> Natural -> SamplingRule)
-> Parser Natural
-> Parser
     (Text -> Text -> Text -> Text -> Text -> Natural -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ReservoirSize")
            Parser
  (Text -> Text -> Text -> Text -> Text -> Natural -> SamplingRule)
-> Parser Text
-> Parser (Text -> Text -> Text -> Text -> Natural -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ServiceName")
            Parser (Text -> Text -> Text -> Text -> Natural -> SamplingRule)
-> Parser Text
-> Parser (Text -> Text -> Text -> Natural -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ServiceType")
            Parser (Text -> Text -> Text -> Natural -> SamplingRule)
-> Parser Text -> Parser (Text -> Text -> Natural -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Host")
            Parser (Text -> Text -> Natural -> SamplingRule)
-> Parser Text -> Parser (Text -> Natural -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"HTTPMethod")
            Parser (Text -> Natural -> SamplingRule)
-> Parser Text -> Parser (Natural -> SamplingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"URLPath")
            Parser (Natural -> SamplingRule)
-> Parser Natural -> Parser SamplingRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Version")
      )

instance Prelude.Hashable SamplingRule

instance Prelude.NFData SamplingRule

instance Core.ToJSON SamplingRule where
  toJSON :: SamplingRule -> Value
toJSON SamplingRule' {Double
Natural
Maybe Text
Maybe (HashMap Text Text)
Text
version :: Natural
uRLPath :: Text
hTTPMethod :: Text
host :: Text
serviceType :: Text
serviceName :: Text
reservoirSize :: Natural
fixedRate :: Double
priority :: Natural
resourceARN :: Text
ruleARN :: Maybe Text
attributes :: Maybe (HashMap Text Text)
ruleName :: Maybe Text
$sel:version:SamplingRule' :: SamplingRule -> Natural
$sel:uRLPath:SamplingRule' :: SamplingRule -> Text
$sel:hTTPMethod:SamplingRule' :: SamplingRule -> Text
$sel:host:SamplingRule' :: SamplingRule -> Text
$sel:serviceType:SamplingRule' :: SamplingRule -> Text
$sel:serviceName:SamplingRule' :: SamplingRule -> Text
$sel:reservoirSize:SamplingRule' :: SamplingRule -> Natural
$sel:fixedRate:SamplingRule' :: SamplingRule -> Double
$sel:priority:SamplingRule' :: SamplingRule -> Natural
$sel:resourceARN:SamplingRule' :: SamplingRule -> Text
$sel:ruleARN:SamplingRule' :: SamplingRule -> Maybe Text
$sel:attributes:SamplingRule' :: SamplingRule -> Maybe (HashMap Text Text)
$sel:ruleName:SamplingRule' :: SamplingRule -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RuleName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
ruleName,
            (Text
"Attributes" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
attributes,
            (Text
"RuleARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
ruleARN,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ResourceARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resourceARN),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Priority" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
priority),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"FixedRate" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Double
fixedRate),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ReservoirSize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
reservoirSize),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ServiceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serviceName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ServiceType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serviceType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Host" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
host),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"HTTPMethod" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
hTTPMethod),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"URLPath" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
uRLPath),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Version" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
version)
          ]
      )