{-# 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.AmplifyUiBuilder.Types.ValueMappings
-- 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.AmplifyUiBuilder.Types.ValueMappings where

import Amazonka.AmplifyUiBuilder.Types.ValueMapping
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

-- | Represents the data binding configuration for a value map.
--
-- /See:/ 'newValueMappings' smart constructor.
data ValueMappings = ValueMappings'
  { -- | The value and display value pairs.
    ValueMappings -> [ValueMapping]
values :: [ValueMapping]
  }
  deriving (ValueMappings -> ValueMappings -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ValueMappings -> ValueMappings -> Bool
$c/= :: ValueMappings -> ValueMappings -> Bool
== :: ValueMappings -> ValueMappings -> Bool
$c== :: ValueMappings -> ValueMappings -> Bool
Prelude.Eq, ReadPrec [ValueMappings]
ReadPrec ValueMappings
Int -> ReadS ValueMappings
ReadS [ValueMappings]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ValueMappings]
$creadListPrec :: ReadPrec [ValueMappings]
readPrec :: ReadPrec ValueMappings
$creadPrec :: ReadPrec ValueMappings
readList :: ReadS [ValueMappings]
$creadList :: ReadS [ValueMappings]
readsPrec :: Int -> ReadS ValueMappings
$creadsPrec :: Int -> ReadS ValueMappings
Prelude.Read, Int -> ValueMappings -> ShowS
[ValueMappings] -> ShowS
ValueMappings -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ValueMappings] -> ShowS
$cshowList :: [ValueMappings] -> ShowS
show :: ValueMappings -> String
$cshow :: ValueMappings -> String
showsPrec :: Int -> ValueMappings -> ShowS
$cshowsPrec :: Int -> ValueMappings -> ShowS
Prelude.Show, forall x. Rep ValueMappings x -> ValueMappings
forall x. ValueMappings -> Rep ValueMappings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ValueMappings x -> ValueMappings
$cfrom :: forall x. ValueMappings -> Rep ValueMappings x
Prelude.Generic)

-- |
-- Create a value of 'ValueMappings' 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:
--
-- 'values', 'valueMappings_values' - The value and display value pairs.
newValueMappings ::
  ValueMappings
newValueMappings :: ValueMappings
newValueMappings =
  ValueMappings' {$sel:values:ValueMappings' :: [ValueMapping]
values = forall a. Monoid a => a
Prelude.mempty}

-- | The value and display value pairs.
valueMappings_values :: Lens.Lens' ValueMappings [ValueMapping]
valueMappings_values :: Lens' ValueMappings [ValueMapping]
valueMappings_values = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ValueMappings' {[ValueMapping]
values :: [ValueMapping]
$sel:values:ValueMappings' :: ValueMappings -> [ValueMapping]
values} -> [ValueMapping]
values) (\s :: ValueMappings
s@ValueMappings' {} [ValueMapping]
a -> ValueMappings
s {$sel:values:ValueMappings' :: [ValueMapping]
values = [ValueMapping]
a} :: ValueMappings) 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 ValueMappings where
  parseJSON :: Value -> Parser ValueMappings
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ValueMappings"
      ( \Object
x ->
          [ValueMapping] -> ValueMappings
ValueMappings'
            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
"values" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ValueMappings where
  hashWithSalt :: Int -> ValueMappings -> Int
hashWithSalt Int
_salt ValueMappings' {[ValueMapping]
values :: [ValueMapping]
$sel:values:ValueMappings' :: ValueMappings -> [ValueMapping]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ValueMapping]
values

instance Prelude.NFData ValueMappings where
  rnf :: ValueMappings -> ()
rnf ValueMappings' {[ValueMapping]
values :: [ValueMapping]
$sel:values:ValueMappings' :: ValueMappings -> [ValueMapping]
..} = forall a. NFData a => a -> ()
Prelude.rnf [ValueMapping]
values

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