{-# 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.ImageBuilder.Types.ComponentParameter
-- 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.ImageBuilder.Types.ComponentParameter 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 a key\/value pair that sets the named component parameter.
--
-- /See:/ 'newComponentParameter' smart constructor.
data ComponentParameter = ComponentParameter'
  { -- | The name of the component parameter to set.
    ComponentParameter -> Text
name :: Prelude.Text,
    -- | Sets the value for the named component parameter.
    ComponentParameter -> [Text]
value :: [Prelude.Text]
  }
  deriving (ComponentParameter -> ComponentParameter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentParameter -> ComponentParameter -> Bool
$c/= :: ComponentParameter -> ComponentParameter -> Bool
== :: ComponentParameter -> ComponentParameter -> Bool
$c== :: ComponentParameter -> ComponentParameter -> Bool
Prelude.Eq, ReadPrec [ComponentParameter]
ReadPrec ComponentParameter
Int -> ReadS ComponentParameter
ReadS [ComponentParameter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComponentParameter]
$creadListPrec :: ReadPrec [ComponentParameter]
readPrec :: ReadPrec ComponentParameter
$creadPrec :: ReadPrec ComponentParameter
readList :: ReadS [ComponentParameter]
$creadList :: ReadS [ComponentParameter]
readsPrec :: Int -> ReadS ComponentParameter
$creadsPrec :: Int -> ReadS ComponentParameter
Prelude.Read, Int -> ComponentParameter -> ShowS
[ComponentParameter] -> ShowS
ComponentParameter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentParameter] -> ShowS
$cshowList :: [ComponentParameter] -> ShowS
show :: ComponentParameter -> String
$cshow :: ComponentParameter -> String
showsPrec :: Int -> ComponentParameter -> ShowS
$cshowsPrec :: Int -> ComponentParameter -> ShowS
Prelude.Show, forall x. Rep ComponentParameter x -> ComponentParameter
forall x. ComponentParameter -> Rep ComponentParameter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ComponentParameter x -> ComponentParameter
$cfrom :: forall x. ComponentParameter -> Rep ComponentParameter x
Prelude.Generic)

-- |
-- Create a value of 'ComponentParameter' 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:
--
-- 'name', 'componentParameter_name' - The name of the component parameter to set.
--
-- 'value', 'componentParameter_value' - Sets the value for the named component parameter.
newComponentParameter ::
  -- | 'name'
  Prelude.Text ->
  ComponentParameter
newComponentParameter :: Text -> ComponentParameter
newComponentParameter Text
pName_ =
  ComponentParameter'
    { $sel:name:ComponentParameter' :: Text
name = Text
pName_,
      $sel:value:ComponentParameter' :: [Text]
value = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the component parameter to set.
componentParameter_name :: Lens.Lens' ComponentParameter Prelude.Text
componentParameter_name :: Lens' ComponentParameter Text
componentParameter_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentParameter' {Text
name :: Text
$sel:name:ComponentParameter' :: ComponentParameter -> Text
name} -> Text
name) (\s :: ComponentParameter
s@ComponentParameter' {} Text
a -> ComponentParameter
s {$sel:name:ComponentParameter' :: Text
name = Text
a} :: ComponentParameter)

-- | Sets the value for the named component parameter.
componentParameter_value :: Lens.Lens' ComponentParameter [Prelude.Text]
componentParameter_value :: Lens' ComponentParameter [Text]
componentParameter_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentParameter' {[Text]
value :: [Text]
$sel:value:ComponentParameter' :: ComponentParameter -> [Text]
value} -> [Text]
value) (\s :: ComponentParameter
s@ComponentParameter' {} [Text]
a -> ComponentParameter
s {$sel:value:ComponentParameter' :: [Text]
value = [Text]
a} :: ComponentParameter) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ComponentParameter where
  hashWithSalt :: Int -> ComponentParameter -> Int
hashWithSalt Int
_salt ComponentParameter' {[Text]
Text
value :: [Text]
name :: Text
$sel:value:ComponentParameter' :: ComponentParameter -> [Text]
$sel:name:ComponentParameter' :: ComponentParameter -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
value

instance Prelude.NFData ComponentParameter where
  rnf :: ComponentParameter -> ()
rnf ComponentParameter' {[Text]
Text
value :: [Text]
name :: Text
$sel:value:ComponentParameter' :: ComponentParameter -> [Text]
$sel:name:ComponentParameter' :: ComponentParameter -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
value

instance Data.ToJSON ComponentParameter where
  toJSON :: ComponentParameter -> Value
toJSON ComponentParameter' {[Text]
Text
value :: [Text]
name :: Text
$sel:value:ComponentParameter' :: ComponentParameter -> [Text]
$sel:name:ComponentParameter' :: ComponentParameter -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
value)
          ]
      )