{-# 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-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.ResourceKey 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 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
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]
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
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. 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'
    { $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 :: Lens' ResourceKey ResourceType
resourceKey_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 :: Lens' ResourceKey Text
resourceKey_resourceId = 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 Data.FromJSON ResourceKey where
  parseJSON :: Value -> Parser ResourceKey
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResourceKey"
      ( \Object
x ->
          ResourceType -> Text -> ResourceKey
ResourceKey'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"resourceType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"resourceId")
      )

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

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"resourceType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ResourceType
resourceType),
            forall a. a -> Maybe a
Prelude.Just (Key
"resourceId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
resourceId)
          ]
      )