{-# 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.CloudWatchEvents.Types.RunCommandParameters
-- 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.CloudWatchEvents.Types.RunCommandParameters where

import Amazonka.CloudWatchEvents.Types.RunCommandTarget
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This parameter contains the criteria (either InstanceIds or a tag) used
-- to specify which EC2 instances are to be sent the command.
--
-- /See:/ 'newRunCommandParameters' smart constructor.
data RunCommandParameters = RunCommandParameters'
  { -- | Currently, we support including only one RunCommandTarget block, which
    -- specifies either an array of InstanceIds or a tag.
    RunCommandParameters -> NonEmpty RunCommandTarget
runCommandTargets :: Prelude.NonEmpty RunCommandTarget
  }
  deriving (RunCommandParameters -> RunCommandParameters -> Bool
(RunCommandParameters -> RunCommandParameters -> Bool)
-> (RunCommandParameters -> RunCommandParameters -> Bool)
-> Eq RunCommandParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RunCommandParameters -> RunCommandParameters -> Bool
$c/= :: RunCommandParameters -> RunCommandParameters -> Bool
== :: RunCommandParameters -> RunCommandParameters -> Bool
$c== :: RunCommandParameters -> RunCommandParameters -> Bool
Prelude.Eq, ReadPrec [RunCommandParameters]
ReadPrec RunCommandParameters
Int -> ReadS RunCommandParameters
ReadS [RunCommandParameters]
(Int -> ReadS RunCommandParameters)
-> ReadS [RunCommandParameters]
-> ReadPrec RunCommandParameters
-> ReadPrec [RunCommandParameters]
-> Read RunCommandParameters
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RunCommandParameters]
$creadListPrec :: ReadPrec [RunCommandParameters]
readPrec :: ReadPrec RunCommandParameters
$creadPrec :: ReadPrec RunCommandParameters
readList :: ReadS [RunCommandParameters]
$creadList :: ReadS [RunCommandParameters]
readsPrec :: Int -> ReadS RunCommandParameters
$creadsPrec :: Int -> ReadS RunCommandParameters
Prelude.Read, Int -> RunCommandParameters -> ShowS
[RunCommandParameters] -> ShowS
RunCommandParameters -> String
(Int -> RunCommandParameters -> ShowS)
-> (RunCommandParameters -> String)
-> ([RunCommandParameters] -> ShowS)
-> Show RunCommandParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RunCommandParameters] -> ShowS
$cshowList :: [RunCommandParameters] -> ShowS
show :: RunCommandParameters -> String
$cshow :: RunCommandParameters -> String
showsPrec :: Int -> RunCommandParameters -> ShowS
$cshowsPrec :: Int -> RunCommandParameters -> ShowS
Prelude.Show, (forall x. RunCommandParameters -> Rep RunCommandParameters x)
-> (forall x. Rep RunCommandParameters x -> RunCommandParameters)
-> Generic RunCommandParameters
forall x. Rep RunCommandParameters x -> RunCommandParameters
forall x. RunCommandParameters -> Rep RunCommandParameters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RunCommandParameters x -> RunCommandParameters
$cfrom :: forall x. RunCommandParameters -> Rep RunCommandParameters x
Prelude.Generic)

-- |
-- Create a value of 'RunCommandParameters' 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:
--
-- 'runCommandTargets', 'runCommandParameters_runCommandTargets' - Currently, we support including only one RunCommandTarget block, which
-- specifies either an array of InstanceIds or a tag.
newRunCommandParameters ::
  -- | 'runCommandTargets'
  Prelude.NonEmpty RunCommandTarget ->
  RunCommandParameters
newRunCommandParameters :: NonEmpty RunCommandTarget -> RunCommandParameters
newRunCommandParameters NonEmpty RunCommandTarget
pRunCommandTargets_ =
  RunCommandParameters' :: NonEmpty RunCommandTarget -> RunCommandParameters
RunCommandParameters'
    { $sel:runCommandTargets:RunCommandParameters' :: NonEmpty RunCommandTarget
runCommandTargets =
        Tagged
  (NonEmpty RunCommandTarget) (Identity (NonEmpty RunCommandTarget))
-> Tagged
     (NonEmpty RunCommandTarget) (Identity (NonEmpty RunCommandTarget))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty RunCommandTarget) (Identity (NonEmpty RunCommandTarget))
 -> Tagged
      (NonEmpty RunCommandTarget) (Identity (NonEmpty RunCommandTarget)))
-> NonEmpty RunCommandTarget -> NonEmpty RunCommandTarget
forall t b. AReview t b -> b -> t
Lens.# NonEmpty RunCommandTarget
pRunCommandTargets_
    }

-- | Currently, we support including only one RunCommandTarget block, which
-- specifies either an array of InstanceIds or a tag.
runCommandParameters_runCommandTargets :: Lens.Lens' RunCommandParameters (Prelude.NonEmpty RunCommandTarget)
runCommandParameters_runCommandTargets :: (NonEmpty RunCommandTarget -> f (NonEmpty RunCommandTarget))
-> RunCommandParameters -> f RunCommandParameters
runCommandParameters_runCommandTargets = (RunCommandParameters -> NonEmpty RunCommandTarget)
-> (RunCommandParameters
    -> NonEmpty RunCommandTarget -> RunCommandParameters)
-> Lens
     RunCommandParameters
     RunCommandParameters
     (NonEmpty RunCommandTarget)
     (NonEmpty RunCommandTarget)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RunCommandParameters' {NonEmpty RunCommandTarget
runCommandTargets :: NonEmpty RunCommandTarget
$sel:runCommandTargets:RunCommandParameters' :: RunCommandParameters -> NonEmpty RunCommandTarget
runCommandTargets} -> NonEmpty RunCommandTarget
runCommandTargets) (\s :: RunCommandParameters
s@RunCommandParameters' {} NonEmpty RunCommandTarget
a -> RunCommandParameters
s {$sel:runCommandTargets:RunCommandParameters' :: NonEmpty RunCommandTarget
runCommandTargets = NonEmpty RunCommandTarget
a} :: RunCommandParameters) ((NonEmpty RunCommandTarget -> f (NonEmpty RunCommandTarget))
 -> RunCommandParameters -> f RunCommandParameters)
-> ((NonEmpty RunCommandTarget -> f (NonEmpty RunCommandTarget))
    -> NonEmpty RunCommandTarget -> f (NonEmpty RunCommandTarget))
-> (NonEmpty RunCommandTarget -> f (NonEmpty RunCommandTarget))
-> RunCommandParameters
-> f RunCommandParameters
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty RunCommandTarget -> f (NonEmpty RunCommandTarget))
-> NonEmpty RunCommandTarget -> f (NonEmpty RunCommandTarget)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON RunCommandParameters where
  parseJSON :: Value -> Parser RunCommandParameters
parseJSON =
    String
-> (Object -> Parser RunCommandParameters)
-> Value
-> Parser RunCommandParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RunCommandParameters"
      ( \Object
x ->
          NonEmpty RunCommandTarget -> RunCommandParameters
RunCommandParameters'
            (NonEmpty RunCommandTarget -> RunCommandParameters)
-> Parser (NonEmpty RunCommandTarget)
-> Parser RunCommandParameters
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty RunCommandTarget)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RunCommandTargets")
      )

instance Prelude.Hashable RunCommandParameters

instance Prelude.NFData RunCommandParameters

instance Core.ToJSON RunCommandParameters where
  toJSON :: RunCommandParameters -> Value
toJSON RunCommandParameters' {NonEmpty RunCommandTarget
runCommandTargets :: NonEmpty RunCommandTarget
$sel:runCommandTargets:RunCommandParameters' :: RunCommandParameters -> NonEmpty RunCommandTarget
..} =
    [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
"RunCommandTargets" Text -> NonEmpty RunCommandTarget -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty RunCommandTarget
runCommandTargets)
          ]
      )