{-# 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-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.ImageBuilder.Types.ComponentParameter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(ComponentParameter -> ComponentParameter -> Bool)
-> (ComponentParameter -> ComponentParameter -> Bool)
-> Eq ComponentParameter
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]
(Int -> ReadS ComponentParameter)
-> ReadS [ComponentParameter]
-> ReadPrec ComponentParameter
-> ReadPrec [ComponentParameter]
-> Read 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
(Int -> ComponentParameter -> ShowS)
-> (ComponentParameter -> String)
-> ([ComponentParameter] -> ShowS)
-> Show ComponentParameter
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. ComponentParameter -> Rep ComponentParameter x)
-> (forall x. Rep ComponentParameter x -> ComponentParameter)
-> Generic ComponentParameter
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' :: Text -> [Text] -> ComponentParameter
ComponentParameter'
    { $sel:name:ComponentParameter' :: Text
name = Text
pName_,
      $sel:value:ComponentParameter' :: [Text]
value = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the component parameter to set.
componentParameter_name :: Lens.Lens' ComponentParameter Prelude.Text
componentParameter_name :: (Text -> f Text) -> ComponentParameter -> f ComponentParameter
componentParameter_name = (ComponentParameter -> Text)
-> (ComponentParameter -> Text -> ComponentParameter)
-> Lens ComponentParameter ComponentParameter Text Text
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 :: ([Text] -> f [Text]) -> ComponentParameter -> f ComponentParameter
componentParameter_value = (ComponentParameter -> [Text])
-> (ComponentParameter -> [Text] -> ComponentParameter)
-> Lens ComponentParameter ComponentParameter [Text] [Text]
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) (([Text] -> f [Text])
 -> ComponentParameter -> f ComponentParameter)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> ComponentParameter
-> f ComponentParameter
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ComponentParameter

instance Prelude.NFData ComponentParameter

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"value" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
value)
          ]
      )