{-# 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.Greengrass.Types.Resource
-- 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.Greengrass.Types.Resource where

import qualified Amazonka.Core as Core
import Amazonka.Greengrass.Types.ResourceDataContainer
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a resource.
--
-- /See:/ 'newResource' smart constructor.
data Resource = Resource'
  { -- | A container of data for all resource types.
    Resource -> ResourceDataContainer
resourceDataContainer :: ResourceDataContainer,
    -- | The resource ID, used to refer to a resource in the Lambda function
    -- configuration. Max length is 128 characters with pattern
    -- \'\'[a-zA-Z0-9:_-]+\'\'. This must be unique within a Greengrass group.
    Resource -> Text
id :: Prelude.Text,
    -- | The descriptive resource name, which is displayed on the AWS IoT
    -- Greengrass console. Max length 128 characters with pattern
    -- \'\'[a-zA-Z0-9:_-]+\'\'. This must be unique within a Greengrass group.
    Resource -> Text
name :: Prelude.Text
  }
  deriving (Resource -> Resource -> Bool
(Resource -> Resource -> Bool)
-> (Resource -> Resource -> Bool) -> Eq Resource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Resource -> Resource -> Bool
$c/= :: Resource -> Resource -> Bool
== :: Resource -> Resource -> Bool
$c== :: Resource -> Resource -> Bool
Prelude.Eq, ReadPrec [Resource]
ReadPrec Resource
Int -> ReadS Resource
ReadS [Resource]
(Int -> ReadS Resource)
-> ReadS [Resource]
-> ReadPrec Resource
-> ReadPrec [Resource]
-> Read Resource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Resource]
$creadListPrec :: ReadPrec [Resource]
readPrec :: ReadPrec Resource
$creadPrec :: ReadPrec Resource
readList :: ReadS [Resource]
$creadList :: ReadS [Resource]
readsPrec :: Int -> ReadS Resource
$creadsPrec :: Int -> ReadS Resource
Prelude.Read, Int -> Resource -> ShowS
[Resource] -> ShowS
Resource -> String
(Int -> Resource -> ShowS)
-> (Resource -> String) -> ([Resource] -> ShowS) -> Show Resource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Resource] -> ShowS
$cshowList :: [Resource] -> ShowS
show :: Resource -> String
$cshow :: Resource -> String
showsPrec :: Int -> Resource -> ShowS
$cshowsPrec :: Int -> Resource -> ShowS
Prelude.Show, (forall x. Resource -> Rep Resource x)
-> (forall x. Rep Resource x -> Resource) -> Generic Resource
forall x. Rep Resource x -> Resource
forall x. Resource -> Rep Resource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Resource x -> Resource
$cfrom :: forall x. Resource -> Rep Resource x
Prelude.Generic)

-- |
-- Create a value of 'Resource' 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:
--
-- 'resourceDataContainer', 'resource_resourceDataContainer' - A container of data for all resource types.
--
-- 'id', 'resource_id' - The resource ID, used to refer to a resource in the Lambda function
-- configuration. Max length is 128 characters with pattern
-- \'\'[a-zA-Z0-9:_-]+\'\'. This must be unique within a Greengrass group.
--
-- 'name', 'resource_name' - The descriptive resource name, which is displayed on the AWS IoT
-- Greengrass console. Max length 128 characters with pattern
-- \'\'[a-zA-Z0-9:_-]+\'\'. This must be unique within a Greengrass group.
newResource ::
  -- | 'resourceDataContainer'
  ResourceDataContainer ->
  -- | 'id'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  Resource
newResource :: ResourceDataContainer -> Text -> Text -> Resource
newResource ResourceDataContainer
pResourceDataContainer_ Text
pId_ Text
pName_ =
  Resource' :: ResourceDataContainer -> Text -> Text -> Resource
Resource'
    { $sel:resourceDataContainer:Resource' :: ResourceDataContainer
resourceDataContainer =
        ResourceDataContainer
pResourceDataContainer_,
      $sel:id:Resource' :: Text
id = Text
pId_,
      $sel:name:Resource' :: Text
name = Text
pName_
    }

-- | A container of data for all resource types.
resource_resourceDataContainer :: Lens.Lens' Resource ResourceDataContainer
resource_resourceDataContainer :: (ResourceDataContainer -> f ResourceDataContainer)
-> Resource -> f Resource
resource_resourceDataContainer = (Resource -> ResourceDataContainer)
-> (Resource -> ResourceDataContainer -> Resource)
-> Lens
     Resource Resource ResourceDataContainer ResourceDataContainer
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {ResourceDataContainer
resourceDataContainer :: ResourceDataContainer
$sel:resourceDataContainer:Resource' :: Resource -> ResourceDataContainer
resourceDataContainer} -> ResourceDataContainer
resourceDataContainer) (\s :: Resource
s@Resource' {} ResourceDataContainer
a -> Resource
s {$sel:resourceDataContainer:Resource' :: ResourceDataContainer
resourceDataContainer = ResourceDataContainer
a} :: Resource)

-- | The resource ID, used to refer to a resource in the Lambda function
-- configuration. Max length is 128 characters with pattern
-- \'\'[a-zA-Z0-9:_-]+\'\'. This must be unique within a Greengrass group.
resource_id :: Lens.Lens' Resource Prelude.Text
resource_id :: (Text -> f Text) -> Resource -> f Resource
resource_id = (Resource -> Text)
-> (Resource -> Text -> Resource)
-> Lens Resource Resource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Text
id :: Text
$sel:id:Resource' :: Resource -> Text
id} -> Text
id) (\s :: Resource
s@Resource' {} Text
a -> Resource
s {$sel:id:Resource' :: Text
id = Text
a} :: Resource)

-- | The descriptive resource name, which is displayed on the AWS IoT
-- Greengrass console. Max length 128 characters with pattern
-- \'\'[a-zA-Z0-9:_-]+\'\'. This must be unique within a Greengrass group.
resource_name :: Lens.Lens' Resource Prelude.Text
resource_name :: (Text -> f Text) -> Resource -> f Resource
resource_name = (Resource -> Text)
-> (Resource -> Text -> Resource)
-> Lens Resource Resource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Text
name :: Text
$sel:name:Resource' :: Resource -> Text
name} -> Text
name) (\s :: Resource
s@Resource' {} Text
a -> Resource
s {$sel:name:Resource' :: Text
name = Text
a} :: Resource)

instance Core.FromJSON Resource where
  parseJSON :: Value -> Parser Resource
parseJSON =
    String -> (Object -> Parser Resource) -> Value -> Parser Resource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Resource"
      ( \Object
x ->
          ResourceDataContainer -> Text -> Text -> Resource
Resource'
            (ResourceDataContainer -> Text -> Text -> Resource)
-> Parser ResourceDataContainer
-> Parser (Text -> Text -> Resource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser ResourceDataContainer
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ResourceDataContainer")
            Parser (Text -> Text -> Resource)
-> Parser Text -> Parser (Text -> Resource)
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
"Id")
            Parser (Text -> Resource) -> Parser Text -> Parser Resource
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
"Name")
      )

instance Prelude.Hashable Resource

instance Prelude.NFData Resource

instance Core.ToJSON Resource where
  toJSON :: Resource -> Value
toJSON Resource' {Text
ResourceDataContainer
name :: Text
id :: Text
resourceDataContainer :: ResourceDataContainer
$sel:name:Resource' :: Resource -> Text
$sel:id:Resource' :: Resource -> Text
$sel:resourceDataContainer:Resource' :: Resource -> ResourceDataContainer
..} =
    [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
"ResourceDataContainer"
                  Text -> ResourceDataContainer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ResourceDataContainer
resourceDataContainer
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )