{-# 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.GreengrassV2.Types.ComponentConfigurationUpdate
-- 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.GreengrassV2.Types.ComponentConfigurationUpdate where

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

-- | Contains information about a deployment\'s update to a component\'s
-- configuration on Greengrass core devices. For more information, see
-- <https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html Update component configurations>
-- in the /IoT Greengrass V2 Developer Guide/.
--
-- /See:/ 'newComponentConfigurationUpdate' smart constructor.
data ComponentConfigurationUpdate = ComponentConfigurationUpdate'
  { -- | The list of configuration nodes to reset to default values on target
    -- devices. Use JSON pointers to specify each node to reset. JSON pointers
    -- start with a forward slash (@\/@) and use forward slashes to separate
    -- the key for each level in the object. For more information, see the
    -- <https://tools.ietf.org/html/rfc6901 JSON pointer specification> and
    -- <https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#reset-configuration-update Reset configuration updates>
    -- in the /IoT Greengrass V2 Developer Guide/.
    ComponentConfigurationUpdate -> Maybe [Text]
reset :: Prelude.Maybe [Prelude.Text],
    -- | A serialized JSON string that contains the configuration object to merge
    -- to target devices. The core device merges this configuration with the
    -- component\'s existing configuration. If this is the first time a
    -- component deploys on a device, the core device merges this configuration
    -- with the component\'s default configuration. This means that the core
    -- device keeps it\'s existing configuration for keys and values that you
    -- don\'t specify in this object. For more information, see
    -- <https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#merge-configuration-update Merge configuration updates>
    -- in the /IoT Greengrass V2 Developer Guide/.
    ComponentConfigurationUpdate -> Maybe Text
merge :: Prelude.Maybe Prelude.Text
  }
  deriving (ComponentConfigurationUpdate
-> ComponentConfigurationUpdate -> Bool
(ComponentConfigurationUpdate
 -> ComponentConfigurationUpdate -> Bool)
-> (ComponentConfigurationUpdate
    -> ComponentConfigurationUpdate -> Bool)
-> Eq ComponentConfigurationUpdate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentConfigurationUpdate
-> ComponentConfigurationUpdate -> Bool
$c/= :: ComponentConfigurationUpdate
-> ComponentConfigurationUpdate -> Bool
== :: ComponentConfigurationUpdate
-> ComponentConfigurationUpdate -> Bool
$c== :: ComponentConfigurationUpdate
-> ComponentConfigurationUpdate -> Bool
Prelude.Eq, ReadPrec [ComponentConfigurationUpdate]
ReadPrec ComponentConfigurationUpdate
Int -> ReadS ComponentConfigurationUpdate
ReadS [ComponentConfigurationUpdate]
(Int -> ReadS ComponentConfigurationUpdate)
-> ReadS [ComponentConfigurationUpdate]
-> ReadPrec ComponentConfigurationUpdate
-> ReadPrec [ComponentConfigurationUpdate]
-> Read ComponentConfigurationUpdate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComponentConfigurationUpdate]
$creadListPrec :: ReadPrec [ComponentConfigurationUpdate]
readPrec :: ReadPrec ComponentConfigurationUpdate
$creadPrec :: ReadPrec ComponentConfigurationUpdate
readList :: ReadS [ComponentConfigurationUpdate]
$creadList :: ReadS [ComponentConfigurationUpdate]
readsPrec :: Int -> ReadS ComponentConfigurationUpdate
$creadsPrec :: Int -> ReadS ComponentConfigurationUpdate
Prelude.Read, Int -> ComponentConfigurationUpdate -> ShowS
[ComponentConfigurationUpdate] -> ShowS
ComponentConfigurationUpdate -> String
(Int -> ComponentConfigurationUpdate -> ShowS)
-> (ComponentConfigurationUpdate -> String)
-> ([ComponentConfigurationUpdate] -> ShowS)
-> Show ComponentConfigurationUpdate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentConfigurationUpdate] -> ShowS
$cshowList :: [ComponentConfigurationUpdate] -> ShowS
show :: ComponentConfigurationUpdate -> String
$cshow :: ComponentConfigurationUpdate -> String
showsPrec :: Int -> ComponentConfigurationUpdate -> ShowS
$cshowsPrec :: Int -> ComponentConfigurationUpdate -> ShowS
Prelude.Show, (forall x.
 ComponentConfigurationUpdate -> Rep ComponentConfigurationUpdate x)
-> (forall x.
    Rep ComponentConfigurationUpdate x -> ComponentConfigurationUpdate)
-> Generic ComponentConfigurationUpdate
forall x.
Rep ComponentConfigurationUpdate x -> ComponentConfigurationUpdate
forall x.
ComponentConfigurationUpdate -> Rep ComponentConfigurationUpdate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ComponentConfigurationUpdate x -> ComponentConfigurationUpdate
$cfrom :: forall x.
ComponentConfigurationUpdate -> Rep ComponentConfigurationUpdate x
Prelude.Generic)

-- |
-- Create a value of 'ComponentConfigurationUpdate' 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:
--
-- 'reset', 'componentConfigurationUpdate_reset' - The list of configuration nodes to reset to default values on target
-- devices. Use JSON pointers to specify each node to reset. JSON pointers
-- start with a forward slash (@\/@) and use forward slashes to separate
-- the key for each level in the object. For more information, see the
-- <https://tools.ietf.org/html/rfc6901 JSON pointer specification> and
-- <https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#reset-configuration-update Reset configuration updates>
-- in the /IoT Greengrass V2 Developer Guide/.
--
-- 'merge', 'componentConfigurationUpdate_merge' - A serialized JSON string that contains the configuration object to merge
-- to target devices. The core device merges this configuration with the
-- component\'s existing configuration. If this is the first time a
-- component deploys on a device, the core device merges this configuration
-- with the component\'s default configuration. This means that the core
-- device keeps it\'s existing configuration for keys and values that you
-- don\'t specify in this object. For more information, see
-- <https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#merge-configuration-update Merge configuration updates>
-- in the /IoT Greengrass V2 Developer Guide/.
newComponentConfigurationUpdate ::
  ComponentConfigurationUpdate
newComponentConfigurationUpdate :: ComponentConfigurationUpdate
newComponentConfigurationUpdate =
  ComponentConfigurationUpdate' :: Maybe [Text] -> Maybe Text -> ComponentConfigurationUpdate
ComponentConfigurationUpdate'
    { $sel:reset:ComponentConfigurationUpdate' :: Maybe [Text]
reset =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:merge:ComponentConfigurationUpdate' :: Maybe Text
merge = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The list of configuration nodes to reset to default values on target
-- devices. Use JSON pointers to specify each node to reset. JSON pointers
-- start with a forward slash (@\/@) and use forward slashes to separate
-- the key for each level in the object. For more information, see the
-- <https://tools.ietf.org/html/rfc6901 JSON pointer specification> and
-- <https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#reset-configuration-update Reset configuration updates>
-- in the /IoT Greengrass V2 Developer Guide/.
componentConfigurationUpdate_reset :: Lens.Lens' ComponentConfigurationUpdate (Prelude.Maybe [Prelude.Text])
componentConfigurationUpdate_reset :: (Maybe [Text] -> f (Maybe [Text]))
-> ComponentConfigurationUpdate -> f ComponentConfigurationUpdate
componentConfigurationUpdate_reset = (ComponentConfigurationUpdate -> Maybe [Text])
-> (ComponentConfigurationUpdate
    -> Maybe [Text] -> ComponentConfigurationUpdate)
-> Lens
     ComponentConfigurationUpdate
     ComponentConfigurationUpdate
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConfigurationUpdate' {Maybe [Text]
reset :: Maybe [Text]
$sel:reset:ComponentConfigurationUpdate' :: ComponentConfigurationUpdate -> Maybe [Text]
reset} -> Maybe [Text]
reset) (\s :: ComponentConfigurationUpdate
s@ComponentConfigurationUpdate' {} Maybe [Text]
a -> ComponentConfigurationUpdate
s {$sel:reset:ComponentConfigurationUpdate' :: Maybe [Text]
reset = Maybe [Text]
a} :: ComponentConfigurationUpdate) ((Maybe [Text] -> f (Maybe [Text]))
 -> ComponentConfigurationUpdate -> f ComponentConfigurationUpdate)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> ComponentConfigurationUpdate
-> f ComponentConfigurationUpdate
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A serialized JSON string that contains the configuration object to merge
-- to target devices. The core device merges this configuration with the
-- component\'s existing configuration. If this is the first time a
-- component deploys on a device, the core device merges this configuration
-- with the component\'s default configuration. This means that the core
-- device keeps it\'s existing configuration for keys and values that you
-- don\'t specify in this object. For more information, see
-- <https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#merge-configuration-update Merge configuration updates>
-- in the /IoT Greengrass V2 Developer Guide/.
componentConfigurationUpdate_merge :: Lens.Lens' ComponentConfigurationUpdate (Prelude.Maybe Prelude.Text)
componentConfigurationUpdate_merge :: (Maybe Text -> f (Maybe Text))
-> ComponentConfigurationUpdate -> f ComponentConfigurationUpdate
componentConfigurationUpdate_merge = (ComponentConfigurationUpdate -> Maybe Text)
-> (ComponentConfigurationUpdate
    -> Maybe Text -> ComponentConfigurationUpdate)
-> Lens
     ComponentConfigurationUpdate
     ComponentConfigurationUpdate
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConfigurationUpdate' {Maybe Text
merge :: Maybe Text
$sel:merge:ComponentConfigurationUpdate' :: ComponentConfigurationUpdate -> Maybe Text
merge} -> Maybe Text
merge) (\s :: ComponentConfigurationUpdate
s@ComponentConfigurationUpdate' {} Maybe Text
a -> ComponentConfigurationUpdate
s {$sel:merge:ComponentConfigurationUpdate' :: Maybe Text
merge = Maybe Text
a} :: ComponentConfigurationUpdate)

instance Core.FromJSON ComponentConfigurationUpdate where
  parseJSON :: Value -> Parser ComponentConfigurationUpdate
parseJSON =
    String
-> (Object -> Parser ComponentConfigurationUpdate)
-> Value
-> Parser ComponentConfigurationUpdate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ComponentConfigurationUpdate"
      ( \Object
x ->
          Maybe [Text] -> Maybe Text -> ComponentConfigurationUpdate
ComponentConfigurationUpdate'
            (Maybe [Text] -> Maybe Text -> ComponentConfigurationUpdate)
-> Parser (Maybe [Text])
-> Parser (Maybe Text -> ComponentConfigurationUpdate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"reset" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> ComponentConfigurationUpdate)
-> Parser (Maybe Text) -> Parser ComponentConfigurationUpdate
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
"merge")
      )

instance
  Prelude.Hashable
    ComponentConfigurationUpdate

instance Prelude.NFData ComponentConfigurationUpdate

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