{-# 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.IotTwinMaker.Types.RelationshipValue
-- 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.IotTwinMaker.Types.RelationshipValue 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

-- | A value that associates a component and an entity.
--
-- /See:/ 'newRelationshipValue' smart constructor.
data RelationshipValue = RelationshipValue'
  { -- | The name of the target component associated with the relationship value.
    RelationshipValue -> Maybe Text
targetComponentName :: Prelude.Maybe Prelude.Text,
    -- | The ID of the target entity associated with this relationship value.
    RelationshipValue -> Maybe Text
targetEntityId :: Prelude.Maybe Prelude.Text
  }
  deriving (RelationshipValue -> RelationshipValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RelationshipValue -> RelationshipValue -> Bool
$c/= :: RelationshipValue -> RelationshipValue -> Bool
== :: RelationshipValue -> RelationshipValue -> Bool
$c== :: RelationshipValue -> RelationshipValue -> Bool
Prelude.Eq, ReadPrec [RelationshipValue]
ReadPrec RelationshipValue
Int -> ReadS RelationshipValue
ReadS [RelationshipValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RelationshipValue]
$creadListPrec :: ReadPrec [RelationshipValue]
readPrec :: ReadPrec RelationshipValue
$creadPrec :: ReadPrec RelationshipValue
readList :: ReadS [RelationshipValue]
$creadList :: ReadS [RelationshipValue]
readsPrec :: Int -> ReadS RelationshipValue
$creadsPrec :: Int -> ReadS RelationshipValue
Prelude.Read, Int -> RelationshipValue -> ShowS
[RelationshipValue] -> ShowS
RelationshipValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RelationshipValue] -> ShowS
$cshowList :: [RelationshipValue] -> ShowS
show :: RelationshipValue -> String
$cshow :: RelationshipValue -> String
showsPrec :: Int -> RelationshipValue -> ShowS
$cshowsPrec :: Int -> RelationshipValue -> ShowS
Prelude.Show, forall x. Rep RelationshipValue x -> RelationshipValue
forall x. RelationshipValue -> Rep RelationshipValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RelationshipValue x -> RelationshipValue
$cfrom :: forall x. RelationshipValue -> Rep RelationshipValue x
Prelude.Generic)

-- |
-- Create a value of 'RelationshipValue' 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:
--
-- 'targetComponentName', 'relationshipValue_targetComponentName' - The name of the target component associated with the relationship value.
--
-- 'targetEntityId', 'relationshipValue_targetEntityId' - The ID of the target entity associated with this relationship value.
newRelationshipValue ::
  RelationshipValue
newRelationshipValue :: RelationshipValue
newRelationshipValue =
  RelationshipValue'
    { $sel:targetComponentName:RelationshipValue' :: Maybe Text
targetComponentName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:targetEntityId:RelationshipValue' :: Maybe Text
targetEntityId = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the target component associated with the relationship value.
relationshipValue_targetComponentName :: Lens.Lens' RelationshipValue (Prelude.Maybe Prelude.Text)
relationshipValue_targetComponentName :: Lens' RelationshipValue (Maybe Text)
relationshipValue_targetComponentName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelationshipValue' {Maybe Text
targetComponentName :: Maybe Text
$sel:targetComponentName:RelationshipValue' :: RelationshipValue -> Maybe Text
targetComponentName} -> Maybe Text
targetComponentName) (\s :: RelationshipValue
s@RelationshipValue' {} Maybe Text
a -> RelationshipValue
s {$sel:targetComponentName:RelationshipValue' :: Maybe Text
targetComponentName = Maybe Text
a} :: RelationshipValue)

-- | The ID of the target entity associated with this relationship value.
relationshipValue_targetEntityId :: Lens.Lens' RelationshipValue (Prelude.Maybe Prelude.Text)
relationshipValue_targetEntityId :: Lens' RelationshipValue (Maybe Text)
relationshipValue_targetEntityId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelationshipValue' {Maybe Text
targetEntityId :: Maybe Text
$sel:targetEntityId:RelationshipValue' :: RelationshipValue -> Maybe Text
targetEntityId} -> Maybe Text
targetEntityId) (\s :: RelationshipValue
s@RelationshipValue' {} Maybe Text
a -> RelationshipValue
s {$sel:targetEntityId:RelationshipValue' :: Maybe Text
targetEntityId = Maybe Text
a} :: RelationshipValue)

instance Data.FromJSON RelationshipValue where
  parseJSON :: Value -> Parser RelationshipValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RelationshipValue"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> RelationshipValue
RelationshipValue'
            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
"targetComponentName")
            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
"targetEntityId")
      )

instance Prelude.Hashable RelationshipValue where
  hashWithSalt :: Int -> RelationshipValue -> Int
hashWithSalt Int
_salt RelationshipValue' {Maybe Text
targetEntityId :: Maybe Text
targetComponentName :: Maybe Text
$sel:targetEntityId:RelationshipValue' :: RelationshipValue -> Maybe Text
$sel:targetComponentName:RelationshipValue' :: RelationshipValue -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
targetComponentName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
targetEntityId

instance Prelude.NFData RelationshipValue where
  rnf :: RelationshipValue -> ()
rnf RelationshipValue' {Maybe Text
targetEntityId :: Maybe Text
targetComponentName :: Maybe Text
$sel:targetEntityId:RelationshipValue' :: RelationshipValue -> Maybe Text
$sel:targetComponentName:RelationshipValue' :: RelationshipValue -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
targetComponentName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
targetEntityId

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