{-# 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.CloudFront.Types.RealtimeLogConfig
-- 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.CloudFront.Types.RealtimeLogConfig where

import Amazonka.CloudFront.Types.EndPoint
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A real-time log configuration.
--
-- /See:/ 'newRealtimeLogConfig' smart constructor.
data RealtimeLogConfig = RealtimeLogConfig'
  { -- | The Amazon Resource Name (ARN) of this real-time log configuration.
    RealtimeLogConfig -> Text
arn :: Prelude.Text,
    -- | The unique name of this real-time log configuration.
    RealtimeLogConfig -> Text
name :: Prelude.Text,
    -- | The sampling rate for this real-time log configuration. The sampling
    -- rate determines the percentage of viewer requests that are represented
    -- in the real-time log data. The sampling rate is an integer between 1 and
    -- 100, inclusive.
    RealtimeLogConfig -> Integer
samplingRate :: Prelude.Integer,
    -- | Contains information about the Amazon Kinesis data stream where you are
    -- sending real-time log data for this real-time log configuration.
    RealtimeLogConfig -> [EndPoint]
endPoints :: [EndPoint],
    -- | A list of fields that are included in each real-time log record. In an
    -- API response, the fields are provided in the same order in which they
    -- are sent to the Amazon Kinesis data stream.
    --
    -- For more information about fields, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/real-time-logs.html#understand-real-time-log-config-fields Real-time log configuration fields>
    -- in the /Amazon CloudFront Developer Guide/.
    RealtimeLogConfig -> [Text]
fields :: [Prelude.Text]
  }
  deriving (RealtimeLogConfig -> RealtimeLogConfig -> Bool
(RealtimeLogConfig -> RealtimeLogConfig -> Bool)
-> (RealtimeLogConfig -> RealtimeLogConfig -> Bool)
-> Eq RealtimeLogConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RealtimeLogConfig -> RealtimeLogConfig -> Bool
$c/= :: RealtimeLogConfig -> RealtimeLogConfig -> Bool
== :: RealtimeLogConfig -> RealtimeLogConfig -> Bool
$c== :: RealtimeLogConfig -> RealtimeLogConfig -> Bool
Prelude.Eq, ReadPrec [RealtimeLogConfig]
ReadPrec RealtimeLogConfig
Int -> ReadS RealtimeLogConfig
ReadS [RealtimeLogConfig]
(Int -> ReadS RealtimeLogConfig)
-> ReadS [RealtimeLogConfig]
-> ReadPrec RealtimeLogConfig
-> ReadPrec [RealtimeLogConfig]
-> Read RealtimeLogConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RealtimeLogConfig]
$creadListPrec :: ReadPrec [RealtimeLogConfig]
readPrec :: ReadPrec RealtimeLogConfig
$creadPrec :: ReadPrec RealtimeLogConfig
readList :: ReadS [RealtimeLogConfig]
$creadList :: ReadS [RealtimeLogConfig]
readsPrec :: Int -> ReadS RealtimeLogConfig
$creadsPrec :: Int -> ReadS RealtimeLogConfig
Prelude.Read, Int -> RealtimeLogConfig -> ShowS
[RealtimeLogConfig] -> ShowS
RealtimeLogConfig -> String
(Int -> RealtimeLogConfig -> ShowS)
-> (RealtimeLogConfig -> String)
-> ([RealtimeLogConfig] -> ShowS)
-> Show RealtimeLogConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RealtimeLogConfig] -> ShowS
$cshowList :: [RealtimeLogConfig] -> ShowS
show :: RealtimeLogConfig -> String
$cshow :: RealtimeLogConfig -> String
showsPrec :: Int -> RealtimeLogConfig -> ShowS
$cshowsPrec :: Int -> RealtimeLogConfig -> ShowS
Prelude.Show, (forall x. RealtimeLogConfig -> Rep RealtimeLogConfig x)
-> (forall x. Rep RealtimeLogConfig x -> RealtimeLogConfig)
-> Generic RealtimeLogConfig
forall x. Rep RealtimeLogConfig x -> RealtimeLogConfig
forall x. RealtimeLogConfig -> Rep RealtimeLogConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RealtimeLogConfig x -> RealtimeLogConfig
$cfrom :: forall x. RealtimeLogConfig -> Rep RealtimeLogConfig x
Prelude.Generic)

-- |
-- Create a value of 'RealtimeLogConfig' 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', 'realtimeLogConfig_arn' - The Amazon Resource Name (ARN) of this real-time log configuration.
--
-- 'name', 'realtimeLogConfig_name' - The unique name of this real-time log configuration.
--
-- 'samplingRate', 'realtimeLogConfig_samplingRate' - The sampling rate for this real-time log configuration. The sampling
-- rate determines the percentage of viewer requests that are represented
-- in the real-time log data. The sampling rate is an integer between 1 and
-- 100, inclusive.
--
-- 'endPoints', 'realtimeLogConfig_endPoints' - Contains information about the Amazon Kinesis data stream where you are
-- sending real-time log data for this real-time log configuration.
--
-- 'fields', 'realtimeLogConfig_fields' - A list of fields that are included in each real-time log record. In an
-- API response, the fields are provided in the same order in which they
-- are sent to the Amazon Kinesis data stream.
--
-- For more information about fields, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/real-time-logs.html#understand-real-time-log-config-fields Real-time log configuration fields>
-- in the /Amazon CloudFront Developer Guide/.
newRealtimeLogConfig ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  -- | 'samplingRate'
  Prelude.Integer ->
  RealtimeLogConfig
newRealtimeLogConfig :: Text -> Text -> Integer -> RealtimeLogConfig
newRealtimeLogConfig Text
pARN_ Text
pName_ Integer
pSamplingRate_ =
  RealtimeLogConfig' :: Text
-> Text -> Integer -> [EndPoint] -> [Text] -> RealtimeLogConfig
RealtimeLogConfig'
    { $sel:arn:RealtimeLogConfig' :: Text
arn = Text
pARN_,
      $sel:name:RealtimeLogConfig' :: Text
name = Text
pName_,
      $sel:samplingRate:RealtimeLogConfig' :: Integer
samplingRate = Integer
pSamplingRate_,
      $sel:endPoints:RealtimeLogConfig' :: [EndPoint]
endPoints = [EndPoint]
forall a. Monoid a => a
Prelude.mempty,
      $sel:fields:RealtimeLogConfig' :: [Text]
fields = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The Amazon Resource Name (ARN) of this real-time log configuration.
realtimeLogConfig_arn :: Lens.Lens' RealtimeLogConfig Prelude.Text
realtimeLogConfig_arn :: (Text -> f Text) -> RealtimeLogConfig -> f RealtimeLogConfig
realtimeLogConfig_arn = (RealtimeLogConfig -> Text)
-> (RealtimeLogConfig -> Text -> RealtimeLogConfig)
-> Lens RealtimeLogConfig RealtimeLogConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RealtimeLogConfig' {Text
arn :: Text
$sel:arn:RealtimeLogConfig' :: RealtimeLogConfig -> Text
arn} -> Text
arn) (\s :: RealtimeLogConfig
s@RealtimeLogConfig' {} Text
a -> RealtimeLogConfig
s {$sel:arn:RealtimeLogConfig' :: Text
arn = Text
a} :: RealtimeLogConfig)

-- | The unique name of this real-time log configuration.
realtimeLogConfig_name :: Lens.Lens' RealtimeLogConfig Prelude.Text
realtimeLogConfig_name :: (Text -> f Text) -> RealtimeLogConfig -> f RealtimeLogConfig
realtimeLogConfig_name = (RealtimeLogConfig -> Text)
-> (RealtimeLogConfig -> Text -> RealtimeLogConfig)
-> Lens RealtimeLogConfig RealtimeLogConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RealtimeLogConfig' {Text
name :: Text
$sel:name:RealtimeLogConfig' :: RealtimeLogConfig -> Text
name} -> Text
name) (\s :: RealtimeLogConfig
s@RealtimeLogConfig' {} Text
a -> RealtimeLogConfig
s {$sel:name:RealtimeLogConfig' :: Text
name = Text
a} :: RealtimeLogConfig)

-- | The sampling rate for this real-time log configuration. The sampling
-- rate determines the percentage of viewer requests that are represented
-- in the real-time log data. The sampling rate is an integer between 1 and
-- 100, inclusive.
realtimeLogConfig_samplingRate :: Lens.Lens' RealtimeLogConfig Prelude.Integer
realtimeLogConfig_samplingRate :: (Integer -> f Integer) -> RealtimeLogConfig -> f RealtimeLogConfig
realtimeLogConfig_samplingRate = (RealtimeLogConfig -> Integer)
-> (RealtimeLogConfig -> Integer -> RealtimeLogConfig)
-> Lens RealtimeLogConfig RealtimeLogConfig Integer Integer
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RealtimeLogConfig' {Integer
samplingRate :: Integer
$sel:samplingRate:RealtimeLogConfig' :: RealtimeLogConfig -> Integer
samplingRate} -> Integer
samplingRate) (\s :: RealtimeLogConfig
s@RealtimeLogConfig' {} Integer
a -> RealtimeLogConfig
s {$sel:samplingRate:RealtimeLogConfig' :: Integer
samplingRate = Integer
a} :: RealtimeLogConfig)

-- | Contains information about the Amazon Kinesis data stream where you are
-- sending real-time log data for this real-time log configuration.
realtimeLogConfig_endPoints :: Lens.Lens' RealtimeLogConfig [EndPoint]
realtimeLogConfig_endPoints :: ([EndPoint] -> f [EndPoint])
-> RealtimeLogConfig -> f RealtimeLogConfig
realtimeLogConfig_endPoints = (RealtimeLogConfig -> [EndPoint])
-> (RealtimeLogConfig -> [EndPoint] -> RealtimeLogConfig)
-> Lens RealtimeLogConfig RealtimeLogConfig [EndPoint] [EndPoint]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RealtimeLogConfig' {[EndPoint]
endPoints :: [EndPoint]
$sel:endPoints:RealtimeLogConfig' :: RealtimeLogConfig -> [EndPoint]
endPoints} -> [EndPoint]
endPoints) (\s :: RealtimeLogConfig
s@RealtimeLogConfig' {} [EndPoint]
a -> RealtimeLogConfig
s {$sel:endPoints:RealtimeLogConfig' :: [EndPoint]
endPoints = [EndPoint]
a} :: RealtimeLogConfig) (([EndPoint] -> f [EndPoint])
 -> RealtimeLogConfig -> f RealtimeLogConfig)
-> (([EndPoint] -> f [EndPoint]) -> [EndPoint] -> f [EndPoint])
-> ([EndPoint] -> f [EndPoint])
-> RealtimeLogConfig
-> f RealtimeLogConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([EndPoint] -> f [EndPoint]) -> [EndPoint] -> f [EndPoint]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of fields that are included in each real-time log record. In an
-- API response, the fields are provided in the same order in which they
-- are sent to the Amazon Kinesis data stream.
--
-- For more information about fields, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/real-time-logs.html#understand-real-time-log-config-fields Real-time log configuration fields>
-- in the /Amazon CloudFront Developer Guide/.
realtimeLogConfig_fields :: Lens.Lens' RealtimeLogConfig [Prelude.Text]
realtimeLogConfig_fields :: ([Text] -> f [Text]) -> RealtimeLogConfig -> f RealtimeLogConfig
realtimeLogConfig_fields = (RealtimeLogConfig -> [Text])
-> (RealtimeLogConfig -> [Text] -> RealtimeLogConfig)
-> Lens RealtimeLogConfig RealtimeLogConfig [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RealtimeLogConfig' {[Text]
fields :: [Text]
$sel:fields:RealtimeLogConfig' :: RealtimeLogConfig -> [Text]
fields} -> [Text]
fields) (\s :: RealtimeLogConfig
s@RealtimeLogConfig' {} [Text]
a -> RealtimeLogConfig
s {$sel:fields:RealtimeLogConfig' :: [Text]
fields = [Text]
a} :: RealtimeLogConfig) (([Text] -> f [Text]) -> RealtimeLogConfig -> f RealtimeLogConfig)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> RealtimeLogConfig
-> f RealtimeLogConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML RealtimeLogConfig where
  parseXML :: [Node] -> Either String RealtimeLogConfig
parseXML [Node]
x =
    Text
-> Text -> Integer -> [EndPoint] -> [Text] -> RealtimeLogConfig
RealtimeLogConfig'
      (Text
 -> Text -> Integer -> [EndPoint] -> [Text] -> RealtimeLogConfig)
-> Either String Text
-> Either
     String
     (Text -> Integer -> [EndPoint] -> [Text] -> RealtimeLogConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ARN")
      Either
  String
  (Text -> Integer -> [EndPoint] -> [Text] -> RealtimeLogConfig)
-> Either String Text
-> Either
     String (Integer -> [EndPoint] -> [Text] -> RealtimeLogConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name")
      Either
  String (Integer -> [EndPoint] -> [Text] -> RealtimeLogConfig)
-> Either String Integer
-> Either String ([EndPoint] -> [Text] -> RealtimeLogConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Integer
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"SamplingRate")
      Either String ([EndPoint] -> [Text] -> RealtimeLogConfig)
-> Either String [EndPoint]
-> Either String ([Text] -> RealtimeLogConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"EndPoints" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String [EndPoint]) -> Either String [EndPoint]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [EndPoint]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member"
                  )
      Either String ([Text] -> RealtimeLogConfig)
-> Either String [Text] -> Either String RealtimeLogConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Fields" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String [Text]) -> Either String [Text]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Field"
                  )

instance Prelude.Hashable RealtimeLogConfig

instance Prelude.NFData RealtimeLogConfig