{-# 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.OpenSearch.Types.LogPublishingOption
-- 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.OpenSearch.Types.LogPublishingOption 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

-- | Specifies whether the Amazon OpenSearch Service domain publishes the
-- OpenSearch application and slow logs to Amazon CloudWatch. For more
-- information, see
-- <https://docs.aws.amazon.com/opensearch-service/latest/developerguide/createdomain-configure-slow-logs.html Monitoring OpenSearch logs with Amazon CloudWatch Logs>.
--
-- After you enable log publishing, you still have to enable the collection
-- of slow logs using the OpenSearch REST API.
--
-- /See:/ 'newLogPublishingOption' smart constructor.
data LogPublishingOption = LogPublishingOption'
  { -- | The Amazon Resource Name (ARN) of the CloudWatch Logs group to publish
    -- logs to.
    LogPublishingOption -> Maybe Text
cloudWatchLogsLogGroupArn :: Prelude.Maybe Prelude.Text,
    -- | Whether the log should be published.
    LogPublishingOption -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool
  }
  deriving (LogPublishingOption -> LogPublishingOption -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LogPublishingOption -> LogPublishingOption -> Bool
$c/= :: LogPublishingOption -> LogPublishingOption -> Bool
== :: LogPublishingOption -> LogPublishingOption -> Bool
$c== :: LogPublishingOption -> LogPublishingOption -> Bool
Prelude.Eq, ReadPrec [LogPublishingOption]
ReadPrec LogPublishingOption
Int -> ReadS LogPublishingOption
ReadS [LogPublishingOption]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LogPublishingOption]
$creadListPrec :: ReadPrec [LogPublishingOption]
readPrec :: ReadPrec LogPublishingOption
$creadPrec :: ReadPrec LogPublishingOption
readList :: ReadS [LogPublishingOption]
$creadList :: ReadS [LogPublishingOption]
readsPrec :: Int -> ReadS LogPublishingOption
$creadsPrec :: Int -> ReadS LogPublishingOption
Prelude.Read, Int -> LogPublishingOption -> ShowS
[LogPublishingOption] -> ShowS
LogPublishingOption -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LogPublishingOption] -> ShowS
$cshowList :: [LogPublishingOption] -> ShowS
show :: LogPublishingOption -> String
$cshow :: LogPublishingOption -> String
showsPrec :: Int -> LogPublishingOption -> ShowS
$cshowsPrec :: Int -> LogPublishingOption -> ShowS
Prelude.Show, forall x. Rep LogPublishingOption x -> LogPublishingOption
forall x. LogPublishingOption -> Rep LogPublishingOption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LogPublishingOption x -> LogPublishingOption
$cfrom :: forall x. LogPublishingOption -> Rep LogPublishingOption x
Prelude.Generic)

-- |
-- Create a value of 'LogPublishingOption' 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:
--
-- 'cloudWatchLogsLogGroupArn', 'logPublishingOption_cloudWatchLogsLogGroupArn' - The Amazon Resource Name (ARN) of the CloudWatch Logs group to publish
-- logs to.
--
-- 'enabled', 'logPublishingOption_enabled' - Whether the log should be published.
newLogPublishingOption ::
  LogPublishingOption
newLogPublishingOption :: LogPublishingOption
newLogPublishingOption =
  LogPublishingOption'
    { $sel:cloudWatchLogsLogGroupArn:LogPublishingOption' :: Maybe Text
cloudWatchLogsLogGroupArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:LogPublishingOption' :: Maybe Bool
enabled = forall a. Maybe a
Prelude.Nothing
    }

-- | The Amazon Resource Name (ARN) of the CloudWatch Logs group to publish
-- logs to.
logPublishingOption_cloudWatchLogsLogGroupArn :: Lens.Lens' LogPublishingOption (Prelude.Maybe Prelude.Text)
logPublishingOption_cloudWatchLogsLogGroupArn :: Lens' LogPublishingOption (Maybe Text)
logPublishingOption_cloudWatchLogsLogGroupArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogPublishingOption' {Maybe Text
cloudWatchLogsLogGroupArn :: Maybe Text
$sel:cloudWatchLogsLogGroupArn:LogPublishingOption' :: LogPublishingOption -> Maybe Text
cloudWatchLogsLogGroupArn} -> Maybe Text
cloudWatchLogsLogGroupArn) (\s :: LogPublishingOption
s@LogPublishingOption' {} Maybe Text
a -> LogPublishingOption
s {$sel:cloudWatchLogsLogGroupArn:LogPublishingOption' :: Maybe Text
cloudWatchLogsLogGroupArn = Maybe Text
a} :: LogPublishingOption)

-- | Whether the log should be published.
logPublishingOption_enabled :: Lens.Lens' LogPublishingOption (Prelude.Maybe Prelude.Bool)
logPublishingOption_enabled :: Lens' LogPublishingOption (Maybe Bool)
logPublishingOption_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogPublishingOption' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:LogPublishingOption' :: LogPublishingOption -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: LogPublishingOption
s@LogPublishingOption' {} Maybe Bool
a -> LogPublishingOption
s {$sel:enabled:LogPublishingOption' :: Maybe Bool
enabled = Maybe Bool
a} :: LogPublishingOption)

instance Data.FromJSON LogPublishingOption where
  parseJSON :: Value -> Parser LogPublishingOption
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LogPublishingOption"
      ( \Object
x ->
          Maybe Text -> Maybe Bool -> LogPublishingOption
LogPublishingOption'
            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
"CloudWatchLogsLogGroupArn")
            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
"Enabled")
      )

instance Prelude.Hashable LogPublishingOption where
  hashWithSalt :: Int -> LogPublishingOption -> Int
hashWithSalt Int
_salt LogPublishingOption' {Maybe Bool
Maybe Text
enabled :: Maybe Bool
cloudWatchLogsLogGroupArn :: Maybe Text
$sel:enabled:LogPublishingOption' :: LogPublishingOption -> Maybe Bool
$sel:cloudWatchLogsLogGroupArn:LogPublishingOption' :: LogPublishingOption -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
cloudWatchLogsLogGroupArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enabled

instance Prelude.NFData LogPublishingOption where
  rnf :: LogPublishingOption -> ()
rnf LogPublishingOption' {Maybe Bool
Maybe Text
enabled :: Maybe Bool
cloudWatchLogsLogGroupArn :: Maybe Text
$sel:enabled:LogPublishingOption' :: LogPublishingOption -> Maybe Bool
$sel:cloudWatchLogsLogGroupArn:LogPublishingOption' :: LogPublishingOption -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
cloudWatchLogsLogGroupArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enabled

instance Data.ToJSON LogPublishingOption where
  toJSON :: LogPublishingOption -> Value
toJSON LogPublishingOption' {Maybe Bool
Maybe Text
enabled :: Maybe Bool
cloudWatchLogsLogGroupArn :: Maybe Text
$sel:enabled:LogPublishingOption' :: LogPublishingOption -> Maybe Bool
$sel:cloudWatchLogsLogGroupArn:LogPublishingOption' :: LogPublishingOption -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CloudWatchLogsLogGroupArn" 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
cloudWatchLogsLogGroupArn,
            (Key
"Enabled" 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 Bool
enabled
          ]
      )