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

-- | 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'
  { -- | 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,
    -- | 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]
  }
  deriving (ComponentConfigurationUpdate
-> ComponentConfigurationUpdate -> Bool
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]
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
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.
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:
--
-- '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/.
--
-- '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/.
newComponentConfigurationUpdate ::
  ComponentConfigurationUpdate
newComponentConfigurationUpdate :: ComponentConfigurationUpdate
newComponentConfigurationUpdate =
  ComponentConfigurationUpdate'
    { $sel:merge:ComponentConfigurationUpdate' :: Maybe Text
merge =
        forall a. Maybe a
Prelude.Nothing,
      $sel:reset:ComponentConfigurationUpdate' :: Maybe [Text]
reset = forall a. Maybe a
Prelude.Nothing
    }

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

-- | 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 :: Lens' ComponentConfigurationUpdate (Maybe [Text])
componentConfigurationUpdate_reset = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.Hashable
    ComponentConfigurationUpdate
  where
  hashWithSalt :: Int -> ComponentConfigurationUpdate -> Int
hashWithSalt Int
_salt ComponentConfigurationUpdate' {Maybe [Text]
Maybe Text
reset :: Maybe [Text]
merge :: Maybe Text
$sel:reset:ComponentConfigurationUpdate' :: ComponentConfigurationUpdate -> Maybe [Text]
$sel:merge:ComponentConfigurationUpdate' :: ComponentConfigurationUpdate -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
merge
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
reset

instance Prelude.NFData ComponentConfigurationUpdate where
  rnf :: ComponentConfigurationUpdate -> ()
rnf ComponentConfigurationUpdate' {Maybe [Text]
Maybe Text
reset :: Maybe [Text]
merge :: Maybe Text
$sel:reset:ComponentConfigurationUpdate' :: ComponentConfigurationUpdate -> Maybe [Text]
$sel:merge:ComponentConfigurationUpdate' :: ComponentConfigurationUpdate -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
merge seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
reset

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