{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ApiGatewayV2.Types.AccessLogSettings where

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

-- | Settings for logging access in a stage.
--
-- /See:/ 'newAccessLogSettings' smart constructor.
data AccessLogSettings = AccessLogSettings'
  { -- | The ARN of the CloudWatch Logs log group to receive access logs.
    AccessLogSettings -> Maybe Text
destinationArn :: Prelude.Maybe Prelude.Text,
    -- | 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
  }
  deriving (AccessLogSettings -> AccessLogSettings -> Bool
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]
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
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. 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:
--
-- 'destinationArn', 'accessLogSettings_destinationArn' - The ARN of the CloudWatch Logs log group to receive access logs.
--
-- '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.
newAccessLogSettings ::
  AccessLogSettings
newAccessLogSettings :: AccessLogSettings
newAccessLogSettings =
  AccessLogSettings'
    { $sel:destinationArn:AccessLogSettings' :: Maybe Text
destinationArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:format:AccessLogSettings' :: Maybe Text
format = forall a. Maybe a
Prelude.Nothing
    }

-- | The ARN of the CloudWatch Logs log group to receive access logs.
accessLogSettings_destinationArn :: Lens.Lens' AccessLogSettings (Prelude.Maybe Prelude.Text)
accessLogSettings_destinationArn :: Lens' AccessLogSettings (Maybe Text)
accessLogSettings_destinationArn = 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)

-- | 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 :: Lens' AccessLogSettings (Maybe Text)
accessLogSettings_format = 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)

instance Data.FromJSON AccessLogSettings where
  parseJSON :: Value -> Parser AccessLogSettings
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AccessLogSettings"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> AccessLogSettings
AccessLogSettings'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"destinationArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"format")
      )

instance Prelude.Hashable AccessLogSettings where
  hashWithSalt :: Int -> AccessLogSettings -> Int
hashWithSalt Int
_salt AccessLogSettings' {Maybe Text
format :: Maybe Text
destinationArn :: Maybe Text
$sel:format:AccessLogSettings' :: AccessLogSettings -> Maybe Text
$sel:destinationArn:AccessLogSettings' :: AccessLogSettings -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
destinationArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
format

instance Prelude.NFData AccessLogSettings where
  rnf :: AccessLogSettings -> ()
rnf AccessLogSettings' {Maybe Text
format :: Maybe Text
destinationArn :: Maybe Text
$sel:format:AccessLogSettings' :: AccessLogSettings -> Maybe Text
$sel:destinationArn:AccessLogSettings' :: AccessLogSettings -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
destinationArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
format

instance Data.ToJSON AccessLogSettings where
  toJSON :: AccessLogSettings -> Value
toJSON AccessLogSettings' {Maybe Text
format :: Maybe Text
destinationArn :: Maybe Text
$sel:format:AccessLogSettings' :: AccessLogSettings -> Maybe Text
$sel:destinationArn:AccessLogSettings' :: AccessLogSettings -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"destinationArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
destinationArn,
            (Key
"format" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
format
          ]
      )