{-# 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.ResourceKey
-- 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.ResourceKey where

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

-- | The details that identify a resource within Config, including the
-- resource type and resource ID.
--
-- /See:/ 'newResourceKey' smart constructor.
data ResourceKey = ResourceKey'
  { -- | The resource type.
    ResourceKey -> ResourceType
resourceType :: ResourceType,
    -- | The ID of the resource (for example., sg-xxxxxx).
    ResourceKey -> Text
resourceId :: Prelude.Text
  }
  deriving (ResourceKey -> ResourceKey -> Bool
(ResourceKey -> ResourceKey -> Bool)
-> (ResourceKey -> ResourceKey -> Bool) -> Eq ResourceKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceKey -> ResourceKey -> Bool
$c/= :: ResourceKey -> ResourceKey -> Bool
== :: ResourceKey -> ResourceKey -> Bool
$c== :: ResourceKey -> ResourceKey -> Bool
Prelude.Eq, ReadPrec [ResourceKey]
ReadPrec ResourceKey
Int -> ReadS ResourceKey
ReadS [ResourceKey]
(Int -> ReadS ResourceKey)
-> ReadS [ResourceKey]
-> ReadPrec ResourceKey
-> ReadPrec [ResourceKey]
-> Read ResourceKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceKey]
$creadListPrec :: ReadPrec [ResourceKey]
readPrec :: ReadPrec ResourceKey
$creadPrec :: ReadPrec ResourceKey
readList :: ReadS [ResourceKey]
$creadList :: ReadS [ResourceKey]
readsPrec :: Int -> ReadS ResourceKey
$creadsPrec :: Int -> ReadS ResourceKey
Prelude.Read, Int -> ResourceKey -> ShowS
[ResourceKey] -> ShowS
ResourceKey -> String
(Int -> ResourceKey -> ShowS)
-> (ResourceKey -> String)
-> ([ResourceKey] -> ShowS)
-> Show ResourceKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceKey] -> ShowS
$cshowList :: [ResourceKey] -> ShowS
show :: ResourceKey -> String
$cshow :: ResourceKey -> String
showsPrec :: Int -> ResourceKey -> ShowS
$cshowsPrec :: Int -> ResourceKey -> ShowS
Prelude.Show, (forall x. ResourceKey -> Rep ResourceKey x)
-> (forall x. Rep ResourceKey x -> ResourceKey)
-> Generic ResourceKey
forall x. Rep ResourceKey x -> ResourceKey
forall x. ResourceKey -> Rep ResourceKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceKey x -> ResourceKey
$cfrom :: forall x. ResourceKey -> Rep ResourceKey x
Prelude.Generic)

-- |
-- Create a value of 'ResourceKey' 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:
--
-- 'resourceType', 'resourceKey_resourceType' - The resource type.
--
-- 'resourceId', 'resourceKey_resourceId' - The ID of the resource (for example., sg-xxxxxx).
newResourceKey ::
  -- | 'resourceType'
  ResourceType ->
  -- | 'resourceId'
  Prelude.Text ->
  ResourceKey
newResourceKey :: ResourceType -> Text -> ResourceKey
newResourceKey ResourceType
pResourceType_ Text
pResourceId_ =
  ResourceKey' :: ResourceType -> Text -> ResourceKey
ResourceKey'
    { $sel:resourceType:ResourceKey' :: ResourceType
resourceType = ResourceType
pResourceType_,
      $sel:resourceId:ResourceKey' :: Text
resourceId = Text
pResourceId_
    }

-- | The resource type.
resourceKey_resourceType :: Lens.Lens' ResourceKey ResourceType
resourceKey_resourceType :: (ResourceType -> f ResourceType) -> ResourceKey -> f ResourceKey
resourceKey_resourceType = (ResourceKey -> ResourceType)
-> (ResourceKey -> ResourceType -> ResourceKey)
-> Lens ResourceKey ResourceKey ResourceType ResourceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceKey' {ResourceType
resourceType :: ResourceType
$sel:resourceType:ResourceKey' :: ResourceKey -> ResourceType
resourceType} -> ResourceType
resourceType) (\s :: ResourceKey
s@ResourceKey' {} ResourceType
a -> ResourceKey
s {$sel:resourceType:ResourceKey' :: ResourceType
resourceType = ResourceType
a} :: ResourceKey)

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

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

instance Prelude.Hashable ResourceKey

instance Prelude.NFData ResourceKey

instance Core.ToJSON ResourceKey where
  toJSON :: ResourceKey -> Value
toJSON ResourceKey' {Text
ResourceType
resourceId :: Text
resourceType :: ResourceType
$sel:resourceId:ResourceKey' :: ResourceKey -> Text
$sel:resourceType:ResourceKey' :: ResourceKey -> ResourceType
..} =
    [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
"resourceType" Text -> ResourceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ResourceType
resourceType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"resourceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resourceId)
          ]
      )