{-# 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.ApiGatewayV2.Types.AccessLogSettings
-- 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.ApiGatewayV2.Types.AccessLogSettings where

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

-- | Settings for logging access in a stage.
--
-- /See:/ 'newAccessLogSettings' smart constructor.
data AccessLogSettings = AccessLogSettings'
  { -- | A single line format of the access logs of data, as specified by
    -- selected $context variables. The format must include at least
    -- \$context.requestId.
    AccessLogSettings -> Maybe Text
format :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the CloudWatch Logs log group to receive access logs.
    AccessLogSettings -> Maybe Text
destinationArn :: Prelude.Maybe Prelude.Text
  }
  deriving (AccessLogSettings -> AccessLogSettings -> Bool
(AccessLogSettings -> AccessLogSettings -> Bool)
-> (AccessLogSettings -> AccessLogSettings -> Bool)
-> Eq AccessLogSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessLogSettings -> AccessLogSettings -> Bool
$c/= :: AccessLogSettings -> AccessLogSettings -> Bool
== :: AccessLogSettings -> AccessLogSettings -> Bool
$c== :: AccessLogSettings -> AccessLogSettings -> Bool
Prelude.Eq, ReadPrec [AccessLogSettings]
ReadPrec AccessLogSettings
Int -> ReadS AccessLogSettings
ReadS [AccessLogSettings]
(Int -> ReadS AccessLogSettings)
-> ReadS [AccessLogSettings]
-> ReadPrec AccessLogSettings
-> ReadPrec [AccessLogSettings]
-> Read AccessLogSettings
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccessLogSettings]
$creadListPrec :: ReadPrec [AccessLogSettings]
readPrec :: ReadPrec AccessLogSettings
$creadPrec :: ReadPrec AccessLogSettings
readList :: ReadS [AccessLogSettings]
$creadList :: ReadS [AccessLogSettings]
readsPrec :: Int -> ReadS AccessLogSettings
$creadsPrec :: Int -> ReadS AccessLogSettings
Prelude.Read, Int -> AccessLogSettings -> ShowS
[AccessLogSettings] -> ShowS
AccessLogSettings -> String
(Int -> AccessLogSettings -> ShowS)
-> (AccessLogSettings -> String)
-> ([AccessLogSettings] -> ShowS)
-> Show AccessLogSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessLogSettings] -> ShowS
$cshowList :: [AccessLogSettings] -> ShowS
show :: AccessLogSettings -> String
$cshow :: AccessLogSettings -> String
showsPrec :: Int -> AccessLogSettings -> ShowS
$cshowsPrec :: Int -> AccessLogSettings -> ShowS
Prelude.Show, (forall x. AccessLogSettings -> Rep AccessLogSettings x)
-> (forall x. Rep AccessLogSettings x -> AccessLogSettings)
-> Generic AccessLogSettings
forall x. Rep AccessLogSettings x -> AccessLogSettings
forall x. AccessLogSettings -> Rep AccessLogSettings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessLogSettings x -> AccessLogSettings
$cfrom :: forall x. AccessLogSettings -> Rep AccessLogSettings x
Prelude.Generic)

-- |
-- Create a value of 'AccessLogSettings' 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:
--
-- 'format', 'accessLogSettings_format' - A single line format of the access logs of data, as specified by
-- selected $context variables. The format must include at least
-- \$context.requestId.
--
-- 'destinationArn', 'accessLogSettings_destinationArn' - The ARN of the CloudWatch Logs log group to receive access logs.
newAccessLogSettings ::
  AccessLogSettings
newAccessLogSettings :: AccessLogSettings
newAccessLogSettings =
  AccessLogSettings' :: Maybe Text -> Maybe Text -> AccessLogSettings
AccessLogSettings'
    { $sel:format:AccessLogSettings' :: Maybe Text
format = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:destinationArn:AccessLogSettings' :: Maybe Text
destinationArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | A single line format of the access logs of data, as specified by
-- selected $context variables. The format must include at least
-- \$context.requestId.
accessLogSettings_format :: Lens.Lens' AccessLogSettings (Prelude.Maybe Prelude.Text)
accessLogSettings_format :: (Maybe Text -> f (Maybe Text))
-> AccessLogSettings -> f AccessLogSettings
accessLogSettings_format = (AccessLogSettings -> Maybe Text)
-> (AccessLogSettings -> Maybe Text -> AccessLogSettings)
-> Lens
     AccessLogSettings AccessLogSettings (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessLogSettings' {Maybe Text
format :: Maybe Text
$sel:format:AccessLogSettings' :: AccessLogSettings -> Maybe Text
format} -> Maybe Text
format) (\s :: AccessLogSettings
s@AccessLogSettings' {} Maybe Text
a -> AccessLogSettings
s {$sel:format:AccessLogSettings' :: Maybe Text
format = Maybe Text
a} :: AccessLogSettings)

-- | The ARN of the CloudWatch Logs log group to receive access logs.
accessLogSettings_destinationArn :: Lens.Lens' AccessLogSettings (Prelude.Maybe Prelude.Text)
accessLogSettings_destinationArn :: (Maybe Text -> f (Maybe Text))
-> AccessLogSettings -> f AccessLogSettings
accessLogSettings_destinationArn = (AccessLogSettings -> Maybe Text)
-> (AccessLogSettings -> Maybe Text -> AccessLogSettings)
-> Lens
     AccessLogSettings AccessLogSettings (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessLogSettings' {Maybe Text
destinationArn :: Maybe Text
$sel:destinationArn:AccessLogSettings' :: AccessLogSettings -> Maybe Text
destinationArn} -> Maybe Text
destinationArn) (\s :: AccessLogSettings
s@AccessLogSettings' {} Maybe Text
a -> AccessLogSettings
s {$sel:destinationArn:AccessLogSettings' :: Maybe Text
destinationArn = Maybe Text
a} :: AccessLogSettings)

instance Core.FromJSON AccessLogSettings where
  parseJSON :: Value -> Parser AccessLogSettings
parseJSON =
    String
-> (Object -> Parser AccessLogSettings)
-> Value
-> Parser AccessLogSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AccessLogSettings"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> AccessLogSettings
AccessLogSettings'
            (Maybe Text -> Maybe Text -> AccessLogSettings)
-> Parser (Maybe Text) -> Parser (Maybe Text -> AccessLogSettings)
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
"format")
            Parser (Maybe Text -> AccessLogSettings)
-> Parser (Maybe Text) -> Parser AccessLogSettings
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
"destinationArn")
      )

instance Prelude.Hashable AccessLogSettings

instance Prelude.NFData AccessLogSettings

instance Core.ToJSON AccessLogSettings where
  toJSON :: AccessLogSettings -> Value
toJSON AccessLogSettings' {Maybe Text
destinationArn :: Maybe Text
format :: Maybe Text
$sel:destinationArn:AccessLogSettings' :: AccessLogSettings -> Maybe Text
$sel:format:AccessLogSettings' :: AccessLogSettings -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"format" 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
format,
            (Text
"destinationArn" 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
destinationArn
          ]
      )