{-# 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.IoT.Types.CloudwatchLogsAction
-- 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.IoT.Types.CloudwatchLogsAction where

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

-- | Describes an action that sends data to CloudWatch Logs.
--
-- /See:/ 'newCloudwatchLogsAction' smart constructor.
data CloudwatchLogsAction = CloudwatchLogsAction'
  { -- | The IAM role that allows access to the CloudWatch log.
    CloudwatchLogsAction -> Text
roleArn :: Prelude.Text,
    -- | The CloudWatch log group to which the action sends data.
    CloudwatchLogsAction -> Text
logGroupName :: Prelude.Text
  }
  deriving (CloudwatchLogsAction -> CloudwatchLogsAction -> Bool
(CloudwatchLogsAction -> CloudwatchLogsAction -> Bool)
-> (CloudwatchLogsAction -> CloudwatchLogsAction -> Bool)
-> Eq CloudwatchLogsAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CloudwatchLogsAction -> CloudwatchLogsAction -> Bool
$c/= :: CloudwatchLogsAction -> CloudwatchLogsAction -> Bool
== :: CloudwatchLogsAction -> CloudwatchLogsAction -> Bool
$c== :: CloudwatchLogsAction -> CloudwatchLogsAction -> Bool
Prelude.Eq, ReadPrec [CloudwatchLogsAction]
ReadPrec CloudwatchLogsAction
Int -> ReadS CloudwatchLogsAction
ReadS [CloudwatchLogsAction]
(Int -> ReadS CloudwatchLogsAction)
-> ReadS [CloudwatchLogsAction]
-> ReadPrec CloudwatchLogsAction
-> ReadPrec [CloudwatchLogsAction]
-> Read CloudwatchLogsAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CloudwatchLogsAction]
$creadListPrec :: ReadPrec [CloudwatchLogsAction]
readPrec :: ReadPrec CloudwatchLogsAction
$creadPrec :: ReadPrec CloudwatchLogsAction
readList :: ReadS [CloudwatchLogsAction]
$creadList :: ReadS [CloudwatchLogsAction]
readsPrec :: Int -> ReadS CloudwatchLogsAction
$creadsPrec :: Int -> ReadS CloudwatchLogsAction
Prelude.Read, Int -> CloudwatchLogsAction -> ShowS
[CloudwatchLogsAction] -> ShowS
CloudwatchLogsAction -> String
(Int -> CloudwatchLogsAction -> ShowS)
-> (CloudwatchLogsAction -> String)
-> ([CloudwatchLogsAction] -> ShowS)
-> Show CloudwatchLogsAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CloudwatchLogsAction] -> ShowS
$cshowList :: [CloudwatchLogsAction] -> ShowS
show :: CloudwatchLogsAction -> String
$cshow :: CloudwatchLogsAction -> String
showsPrec :: Int -> CloudwatchLogsAction -> ShowS
$cshowsPrec :: Int -> CloudwatchLogsAction -> ShowS
Prelude.Show, (forall x. CloudwatchLogsAction -> Rep CloudwatchLogsAction x)
-> (forall x. Rep CloudwatchLogsAction x -> CloudwatchLogsAction)
-> Generic CloudwatchLogsAction
forall x. Rep CloudwatchLogsAction x -> CloudwatchLogsAction
forall x. CloudwatchLogsAction -> Rep CloudwatchLogsAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CloudwatchLogsAction x -> CloudwatchLogsAction
$cfrom :: forall x. CloudwatchLogsAction -> Rep CloudwatchLogsAction x
Prelude.Generic)

-- |
-- Create a value of 'CloudwatchLogsAction' 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:
--
-- 'roleArn', 'cloudwatchLogsAction_roleArn' - The IAM role that allows access to the CloudWatch log.
--
-- 'logGroupName', 'cloudwatchLogsAction_logGroupName' - The CloudWatch log group to which the action sends data.
newCloudwatchLogsAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'logGroupName'
  Prelude.Text ->
  CloudwatchLogsAction
newCloudwatchLogsAction :: Text -> Text -> CloudwatchLogsAction
newCloudwatchLogsAction Text
pRoleArn_ Text
pLogGroupName_ =
  CloudwatchLogsAction' :: Text -> Text -> CloudwatchLogsAction
CloudwatchLogsAction'
    { $sel:roleArn:CloudwatchLogsAction' :: Text
roleArn = Text
pRoleArn_,
      $sel:logGroupName:CloudwatchLogsAction' :: Text
logGroupName = Text
pLogGroupName_
    }

-- | The IAM role that allows access to the CloudWatch log.
cloudwatchLogsAction_roleArn :: Lens.Lens' CloudwatchLogsAction Prelude.Text
cloudwatchLogsAction_roleArn :: (Text -> f Text) -> CloudwatchLogsAction -> f CloudwatchLogsAction
cloudwatchLogsAction_roleArn = (CloudwatchLogsAction -> Text)
-> (CloudwatchLogsAction -> Text -> CloudwatchLogsAction)
-> Lens CloudwatchLogsAction CloudwatchLogsAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloudwatchLogsAction' {Text
roleArn :: Text
$sel:roleArn:CloudwatchLogsAction' :: CloudwatchLogsAction -> Text
roleArn} -> Text
roleArn) (\s :: CloudwatchLogsAction
s@CloudwatchLogsAction' {} Text
a -> CloudwatchLogsAction
s {$sel:roleArn:CloudwatchLogsAction' :: Text
roleArn = Text
a} :: CloudwatchLogsAction)

-- | The CloudWatch log group to which the action sends data.
cloudwatchLogsAction_logGroupName :: Lens.Lens' CloudwatchLogsAction Prelude.Text
cloudwatchLogsAction_logGroupName :: (Text -> f Text) -> CloudwatchLogsAction -> f CloudwatchLogsAction
cloudwatchLogsAction_logGroupName = (CloudwatchLogsAction -> Text)
-> (CloudwatchLogsAction -> Text -> CloudwatchLogsAction)
-> Lens CloudwatchLogsAction CloudwatchLogsAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloudwatchLogsAction' {Text
logGroupName :: Text
$sel:logGroupName:CloudwatchLogsAction' :: CloudwatchLogsAction -> Text
logGroupName} -> Text
logGroupName) (\s :: CloudwatchLogsAction
s@CloudwatchLogsAction' {} Text
a -> CloudwatchLogsAction
s {$sel:logGroupName:CloudwatchLogsAction' :: Text
logGroupName = Text
a} :: CloudwatchLogsAction)

instance Core.FromJSON CloudwatchLogsAction where
  parseJSON :: Value -> Parser CloudwatchLogsAction
parseJSON =
    String
-> (Object -> Parser CloudwatchLogsAction)
-> Value
-> Parser CloudwatchLogsAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CloudwatchLogsAction"
      ( \Object
x ->
          Text -> Text -> CloudwatchLogsAction
CloudwatchLogsAction'
            (Text -> Text -> CloudwatchLogsAction)
-> Parser Text -> Parser (Text -> CloudwatchLogsAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"roleArn")
            Parser (Text -> CloudwatchLogsAction)
-> Parser Text -> Parser CloudwatchLogsAction
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
"logGroupName")
      )

instance Prelude.Hashable CloudwatchLogsAction

instance Prelude.NFData CloudwatchLogsAction

instance Core.ToJSON CloudwatchLogsAction where
  toJSON :: CloudwatchLogsAction -> Value
toJSON CloudwatchLogsAction' {Text
logGroupName :: Text
roleArn :: Text
$sel:logGroupName:CloudwatchLogsAction' :: CloudwatchLogsAction -> Text
$sel:roleArn:CloudwatchLogsAction' :: CloudwatchLogsAction -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"logGroupName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
logGroupName)
          ]
      )