{-# 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.Config.Types.ResourceValue
-- 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.Config.Types.ResourceValue where

import Amazonka.Config.Types.ResourceValueType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The dynamic value of the resource.
--
-- /See:/ 'newResourceValue' smart constructor.
data ResourceValue = ResourceValue'
  { -- | The value is a resource ID.
    ResourceValue -> ResourceValueType
value :: ResourceValueType
  }
  deriving (ResourceValue -> ResourceValue -> Bool
(ResourceValue -> ResourceValue -> Bool)
-> (ResourceValue -> ResourceValue -> Bool) -> Eq ResourceValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceValue -> ResourceValue -> Bool
$c/= :: ResourceValue -> ResourceValue -> Bool
== :: ResourceValue -> ResourceValue -> Bool
$c== :: ResourceValue -> ResourceValue -> Bool
Prelude.Eq, ReadPrec [ResourceValue]
ReadPrec ResourceValue
Int -> ReadS ResourceValue
ReadS [ResourceValue]
(Int -> ReadS ResourceValue)
-> ReadS [ResourceValue]
-> ReadPrec ResourceValue
-> ReadPrec [ResourceValue]
-> Read ResourceValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceValue]
$creadListPrec :: ReadPrec [ResourceValue]
readPrec :: ReadPrec ResourceValue
$creadPrec :: ReadPrec ResourceValue
readList :: ReadS [ResourceValue]
$creadList :: ReadS [ResourceValue]
readsPrec :: Int -> ReadS ResourceValue
$creadsPrec :: Int -> ReadS ResourceValue
Prelude.Read, Int -> ResourceValue -> ShowS
[ResourceValue] -> ShowS
ResourceValue -> String
(Int -> ResourceValue -> ShowS)
-> (ResourceValue -> String)
-> ([ResourceValue] -> ShowS)
-> Show ResourceValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceValue] -> ShowS
$cshowList :: [ResourceValue] -> ShowS
show :: ResourceValue -> String
$cshow :: ResourceValue -> String
showsPrec :: Int -> ResourceValue -> ShowS
$cshowsPrec :: Int -> ResourceValue -> ShowS
Prelude.Show, (forall x. ResourceValue -> Rep ResourceValue x)
-> (forall x. Rep ResourceValue x -> ResourceValue)
-> Generic ResourceValue
forall x. Rep ResourceValue x -> ResourceValue
forall x. ResourceValue -> Rep ResourceValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceValue x -> ResourceValue
$cfrom :: forall x. ResourceValue -> Rep ResourceValue x
Prelude.Generic)

-- |
-- Create a value of 'ResourceValue' 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:
--
-- 'value', 'resourceValue_value' - The value is a resource ID.
newResourceValue ::
  -- | 'value'
  ResourceValueType ->
  ResourceValue
newResourceValue :: ResourceValueType -> ResourceValue
newResourceValue ResourceValueType
pValue_ =
  ResourceValue' :: ResourceValueType -> ResourceValue
ResourceValue' {$sel:value:ResourceValue' :: ResourceValueType
value = ResourceValueType
pValue_}

-- | The value is a resource ID.
resourceValue_value :: Lens.Lens' ResourceValue ResourceValueType
resourceValue_value :: (ResourceValueType -> f ResourceValueType)
-> ResourceValue -> f ResourceValue
resourceValue_value = (ResourceValue -> ResourceValueType)
-> (ResourceValue -> ResourceValueType -> ResourceValue)
-> Lens
     ResourceValue ResourceValue ResourceValueType ResourceValueType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceValue' {ResourceValueType
value :: ResourceValueType
$sel:value:ResourceValue' :: ResourceValue -> ResourceValueType
value} -> ResourceValueType
value) (\s :: ResourceValue
s@ResourceValue' {} ResourceValueType
a -> ResourceValue
s {$sel:value:ResourceValue' :: ResourceValueType
value = ResourceValueType
a} :: ResourceValue)

instance Core.FromJSON ResourceValue where
  parseJSON :: Value -> Parser ResourceValue
parseJSON =
    String
-> (Object -> Parser ResourceValue)
-> Value
-> Parser ResourceValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourceValue"
      ( \Object
x ->
          ResourceValueType -> ResourceValue
ResourceValue' (ResourceValueType -> ResourceValue)
-> Parser ResourceValueType -> Parser ResourceValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser ResourceValueType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Value")
      )

instance Prelude.Hashable ResourceValue

instance Prelude.NFData ResourceValue

instance Core.ToJSON ResourceValue where
  toJSON :: ResourceValue -> Value
toJSON ResourceValue' {ResourceValueType
value :: ResourceValueType
$sel:value:ResourceValue' :: ResourceValue -> ResourceValueType
..} =
    [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
"Value" Text -> ResourceValueType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ResourceValueType
value)]
      )