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

import Amazonka.Config.Types.ResourceType
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

-- | The relationship of the related resource to the main resource.
--
-- /See:/ 'newRelationship' smart constructor.
data Relationship = Relationship'
  { -- | The type of relationship with the related resource.
    Relationship -> Maybe Text
relationshipName :: Prelude.Maybe Prelude.Text,
    -- | The ID of the related resource (for example, @sg-xxxxxx@).
    Relationship -> Maybe Text
resourceId :: Prelude.Maybe Prelude.Text,
    -- | The custom name of the related resource, if available.
    Relationship -> Maybe Text
resourceName :: Prelude.Maybe Prelude.Text,
    -- | The resource type of the related resource.
    Relationship -> Maybe ResourceType
resourceType :: Prelude.Maybe ResourceType
  }
  deriving (Relationship -> Relationship -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Relationship -> Relationship -> Bool
$c/= :: Relationship -> Relationship -> Bool
== :: Relationship -> Relationship -> Bool
$c== :: Relationship -> Relationship -> Bool
Prelude.Eq, ReadPrec [Relationship]
ReadPrec Relationship
Int -> ReadS Relationship
ReadS [Relationship]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Relationship]
$creadListPrec :: ReadPrec [Relationship]
readPrec :: ReadPrec Relationship
$creadPrec :: ReadPrec Relationship
readList :: ReadS [Relationship]
$creadList :: ReadS [Relationship]
readsPrec :: Int -> ReadS Relationship
$creadsPrec :: Int -> ReadS Relationship
Prelude.Read, Int -> Relationship -> ShowS
[Relationship] -> ShowS
Relationship -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Relationship] -> ShowS
$cshowList :: [Relationship] -> ShowS
show :: Relationship -> String
$cshow :: Relationship -> String
showsPrec :: Int -> Relationship -> ShowS
$cshowsPrec :: Int -> Relationship -> ShowS
Prelude.Show, forall x. Rep Relationship x -> Relationship
forall x. Relationship -> Rep Relationship x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Relationship x -> Relationship
$cfrom :: forall x. Relationship -> Rep Relationship x
Prelude.Generic)

-- |
-- Create a value of 'Relationship' 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:
--
-- 'relationshipName', 'relationship_relationshipName' - The type of relationship with the related resource.
--
-- 'resourceId', 'relationship_resourceId' - The ID of the related resource (for example, @sg-xxxxxx@).
--
-- 'resourceName', 'relationship_resourceName' - The custom name of the related resource, if available.
--
-- 'resourceType', 'relationship_resourceType' - The resource type of the related resource.
newRelationship ::
  Relationship
newRelationship :: Relationship
newRelationship =
  Relationship'
    { $sel:relationshipName:Relationship' :: Maybe Text
relationshipName = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceId:Relationship' :: Maybe Text
resourceId = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceName:Relationship' :: Maybe Text
resourceName = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:Relationship' :: Maybe ResourceType
resourceType = forall a. Maybe a
Prelude.Nothing
    }

-- | The type of relationship with the related resource.
relationship_relationshipName :: Lens.Lens' Relationship (Prelude.Maybe Prelude.Text)
relationship_relationshipName :: Lens' Relationship (Maybe Text)
relationship_relationshipName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Relationship' {Maybe Text
relationshipName :: Maybe Text
$sel:relationshipName:Relationship' :: Relationship -> Maybe Text
relationshipName} -> Maybe Text
relationshipName) (\s :: Relationship
s@Relationship' {} Maybe Text
a -> Relationship
s {$sel:relationshipName:Relationship' :: Maybe Text
relationshipName = Maybe Text
a} :: Relationship)

-- | The ID of the related resource (for example, @sg-xxxxxx@).
relationship_resourceId :: Lens.Lens' Relationship (Prelude.Maybe Prelude.Text)
relationship_resourceId :: Lens' Relationship (Maybe Text)
relationship_resourceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Relationship' {Maybe Text
resourceId :: Maybe Text
$sel:resourceId:Relationship' :: Relationship -> Maybe Text
resourceId} -> Maybe Text
resourceId) (\s :: Relationship
s@Relationship' {} Maybe Text
a -> Relationship
s {$sel:resourceId:Relationship' :: Maybe Text
resourceId = Maybe Text
a} :: Relationship)

-- | The custom name of the related resource, if available.
relationship_resourceName :: Lens.Lens' Relationship (Prelude.Maybe Prelude.Text)
relationship_resourceName :: Lens' Relationship (Maybe Text)
relationship_resourceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Relationship' {Maybe Text
resourceName :: Maybe Text
$sel:resourceName:Relationship' :: Relationship -> Maybe Text
resourceName} -> Maybe Text
resourceName) (\s :: Relationship
s@Relationship' {} Maybe Text
a -> Relationship
s {$sel:resourceName:Relationship' :: Maybe Text
resourceName = Maybe Text
a} :: Relationship)

-- | The resource type of the related resource.
relationship_resourceType :: Lens.Lens' Relationship (Prelude.Maybe ResourceType)
relationship_resourceType :: Lens' Relationship (Maybe ResourceType)
relationship_resourceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Relationship' {Maybe ResourceType
resourceType :: Maybe ResourceType
$sel:resourceType:Relationship' :: Relationship -> Maybe ResourceType
resourceType} -> Maybe ResourceType
resourceType) (\s :: Relationship
s@Relationship' {} Maybe ResourceType
a -> Relationship
s {$sel:resourceType:Relationship' :: Maybe ResourceType
resourceType = Maybe ResourceType
a} :: Relationship)

instance Data.FromJSON Relationship where
  parseJSON :: Value -> Parser Relationship
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Relationship"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Maybe ResourceType -> Relationship
Relationship'
            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
"relationshipName")
            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
"resourceId")
            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
"resourceName")
            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
"resourceType")
      )

instance Prelude.Hashable Relationship where
  hashWithSalt :: Int -> Relationship -> Int
hashWithSalt Int
_salt Relationship' {Maybe Text
Maybe ResourceType
resourceType :: Maybe ResourceType
resourceName :: Maybe Text
resourceId :: Maybe Text
relationshipName :: Maybe Text
$sel:resourceType:Relationship' :: Relationship -> Maybe ResourceType
$sel:resourceName:Relationship' :: Relationship -> Maybe Text
$sel:resourceId:Relationship' :: Relationship -> Maybe Text
$sel:relationshipName:Relationship' :: Relationship -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
relationshipName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
resourceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
resourceName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ResourceType
resourceType

instance Prelude.NFData Relationship where
  rnf :: Relationship -> ()
rnf Relationship' {Maybe Text
Maybe ResourceType
resourceType :: Maybe ResourceType
resourceName :: Maybe Text
resourceId :: Maybe Text
relationshipName :: Maybe Text
$sel:resourceType:Relationship' :: Relationship -> Maybe ResourceType
$sel:resourceName:Relationship' :: Relationship -> Maybe Text
$sel:resourceId:Relationship' :: Relationship -> Maybe Text
$sel:relationshipName:Relationship' :: Relationship -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
relationshipName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ResourceType
resourceType